From f2379acaf4cfdfe49d561a63726629e5ecf05153 Mon Sep 17 00:00:00 2001 From: redae Date: Sun, 1 Sep 2019 13:15:17 +0100 Subject: [PATCH 1/4] Using forward slash to build a full path consistently with the output of file.expand function --- R/misc-functions.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/misc-functions.R b/R/misc-functions.R index 2054214..3373d93 100644 --- a/R/misc-functions.R +++ b/R/misc-functions.R @@ -9,7 +9,7 @@ # Parse file name and path if (file == "") file <- paste0("ukb-schemas-", date_str, ".sqlite") - full_path <- paste0(path.expand(path), "\\", file) + full_path <- paste0(path.expand(path), "/", file) # If `file`` exists, session is `interactive()` and `!overwrite`, then prompt # to overwrite the file @@ -92,4 +92,4 @@ invisible(TRUE) -} \ No newline at end of file +} From 679260c1f8c50ae251ccb883effe62589ddb0bec Mon Sep 17 00:00:00 2001 From: redae Date: Sun, 1 Sep 2019 13:16:55 +0100 Subject: [PATCH 2/4] Added a manual check for open connections in Unix systems before trying to delete the database file --- R/misc-functions.R | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/R/misc-functions.R b/R/misc-functions.R index 3373d93..f519599 100644 --- a/R/misc-functions.R +++ b/R/misc-functions.R @@ -22,8 +22,18 @@ } if (!isTRUE(overwrite)) stop(UKBSCHEMAS_ERRORS$OVERWRITE) - else tryCatch( - file.remove(full_path), + else tryCatch({ + if (.Platform$OS.type == "unix"){ + sys_command <- paste("lsof", full_path, "| wc -l") + processes_using_file <- as.numeric(system(sys_command, intern = TRUE, + ignore.stdout = TRUE, + ignore.stderr = TRUE)) + if (processes_using_file>1) { + stop(UKBSCHEMAS_ERRORS$FAILED_OVERWRITE) + } + } + file.remove(full_path) + }, error = function(err) { stop(UKBSCHEMAS_ERRORS$FAILED_OVERWRITE) }, @@ -92,4 +102,4 @@ invisible(TRUE) -} +} \ No newline at end of file From 20bbc94b9609757ec74ad19dc5b0e2af6f1f2059 Mon Sep 17 00:00:00 2001 From: redae Date: Sun, 1 Sep 2019 13:42:45 +0100 Subject: [PATCH 3/4] Updated test files. Not to skip when system is not windows --- tests/testthat/test-save-db.R | 3 --- tests/testthat/test-ukbschemas-db.R | 3 --- 2 files changed, 6 deletions(-) diff --git a/tests/testthat/test-save-db.R b/tests/testthat/test-save-db.R index 81c94a9..85ac88c 100644 --- a/tests/testthat/test-save-db.R +++ b/tests/testthat/test-save-db.R @@ -72,9 +72,6 @@ test_that("save_db() fails on overwrite = FALSE, non-interactive", { test_that("save_db() fails to overwrite when db is connected", { - # This only seems to work on Windows - skip_if_not(.Platform$OS.type == "windows", "Skipping test if not Windows") - db_file <- test_db_file() expect_error( diff --git a/tests/testthat/test-ukbschemas-db.R b/tests/testthat/test-ukbschemas-db.R index 75033cc..70de563 100644 --- a/tests/testthat/test-ukbschemas-db.R +++ b/tests/testthat/test-ukbschemas-db.R @@ -84,9 +84,6 @@ test_that("ukbschemas_db() fails on overwrite = FALSE, non-interactive", { test_that("ukbschemas_db() fails to overwrite when db is connected", { - # This only seems to work on Windows - skip_if_not(.Platform$OS.type == "windows", "Skipping test if not Windows") - db_file <- test_db_file() expect_error( From d9571bdcde2dfb2adb6cb5dd47cc8b312819286f Mon Sep 17 00:00:00 2001 From: redae Date: Sun, 1 Sep 2019 15:22:27 +0100 Subject: [PATCH 4/4] Prefixed row_number() with dplyr::. Not doing so is deprecated, and the warning indicating that was making the build fail. --- R/tidy-schemas.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tidy-schemas.R b/R/tidy-schemas.R index 1d34bcf..1397e5e 100644 --- a/R/tidy-schemas.R +++ b/R/tidy-schemas.R @@ -61,7 +61,7 @@ dplyr::mutate(.x, parent_id = NA, selectable = NA) %>% dplyr::mutate(type = type, value = as.character(value)) %>% dplyr::group_by(encoding_id) %>% - dplyr::mutate(code_id = row_number()) %>% + dplyr::mutate(code_id = dplyr::row_number()) %>% dplyr::ungroup() } )