Skip to content

Commit 2bf2d6a

Browse files
FIX: use seq_along() for safer iteration (#149) (#175)
1 parent a112181 commit 2bf2d6a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

R/convert.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
#' # download and convert data
3636
#' dates_1 <- c(start = "2020-02-17", end = "2020-02-18")
3737
#' db_2 <- spod_convert(
38-
#' type = "number_of_trips",
39-
#' zones = "distr",
40-
#' dates = dates_1,
41-
#' overwrite = TRUE
38+
#' type = "number_of_trips",
39+
#' zones = "distr",
40+
#' dates = dates_1,
41+
#' overwrite = TRUE
4242
#' )
4343
#'
4444
#' # now connect to the converted data
@@ -204,7 +204,7 @@ spod_convert <- function(
204204
duckdb_target <- save_path
205205
# else check if it is a path to a folder
206206
# basically check that the path does not end with any other file extension other than .duckdb and then consider it as path to folder
207-
} else if (!grepl('\\.[a-zA-Z0-9]+$', save_path)) {
207+
} else if (!grepl("\\.[a-zA-Z0-9]+$", save_path)) {
208208
save_format <- "parquet"
209209
}
210210
}
@@ -322,7 +322,7 @@ spod_convert <- function(
322322
# find all views that contain csv in any case
323323
tables_list <- tables_list[stringr::str_detect(tables_list, "csv")]
324324
if (length(tables_list) > 0) {
325-
for (i in 1:length(tables_list)) {
325+
for (i in seq_along(tables_list)) {
326326
sql_drop_view <- dplyr::sql(
327327
glue::glue(
328328
"DROP VIEW IF EXISTS {tables_list[i]};"
@@ -339,7 +339,7 @@ spod_convert <- function(
339339
# if save_format is parquet
340340
need_to_return_parquet_files <- FALSE # will change in the if below if needed
341341
if (save_format == "parquet") {
342-
if (overwrite == FALSE | overwrite == 'update') {
342+
if (overwrite == FALSE | overwrite == "update") {
343343
# check if there are any existing parquet files in the save_path
344344
parquet_files <- fs::dir_ls(
345345
save_path,
@@ -355,14 +355,14 @@ spod_convert <- function(
355355
"What should be done? [D]elete all existing files in the target folder and convert all requested data from scratch? [U]pdate the folder with any new data while keeping the existing files? [C]ancel and quit? (D/U/C): "
356356
)
357357
}
358-
if (overwrite == 'update' & length(parquet_files) > 0) {
358+
if (overwrite == "update" & length(parquet_files) > 0) {
359359
response <- overwrite
360360
}
361361
if (
362-
(overwrite == 'update' | overwrite == FALSE) &
362+
(overwrite == "update" | overwrite == FALSE) &
363363
length(parquet_files) == 0
364364
) {
365-
response <- 'skip'
365+
response <- "skip"
366366
overwrite <- TRUE
367367
}
368368

0 commit comments

Comments
 (0)