From ae1599b246ea65711c3a1e5ab51ab7fcfd372049 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 29 Apr 2021 15:42:13 -0500 Subject: [PATCH 1/8] Don't build vignettes --- .github/workflows/R-CMD-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index ddbd6ba5e..7c181ad2c 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -81,7 +81,7 @@ jobs: - name: Check env: _R_CHECK_CRAN_INCOMING_REMOTE_: false - run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") + run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), build_args = "--no-build-vignettes", error_on = "warning", check_dir = "check") shell: Rscript {0} - name: Upload check results From 10dd828069b75b6ecbf22e193e5e43a8bfa9c3ed Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 29 Apr 2021 15:54:31 -0500 Subject: [PATCH 2/8] Focus on windows --- .github/workflows/R-CMD-check.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 7c181ad2c..cd637a355 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -23,9 +23,9 @@ jobs: matrix: config: - {os: windows-latest, r: 'release'} - - {os: macOS-latest, r: 'release'} - - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + # - {os: macOS-latest, r: 'release'} + # - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + # - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true From df9e7ae6f392c5a6859c50f81aac89993b51b3e5 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 29 Apr 2021 15:57:22 -0500 Subject: [PATCH 3/8] Add some print debugging --- R/board_local.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/board_local.R b/R/board_local.R index 987cf7538..2b3e3131a 100644 --- a/R/board_local.R +++ b/R/board_local.R @@ -143,6 +143,7 @@ pin_store.pins_board_local <- function(board, name, path, metadata, #' @export pin_meta.pins_board_local <- function(board, name, version = NULL, ...) { + print(name) check_name(name) path_pin <- fs::path(board$path, name) if (!fs::dir_exists(path_pin)) { @@ -152,6 +153,7 @@ pin_meta.pins_board_local <- function(board, name, version = NULL, ...) { # Fallback to old structure meta_pin <- read_meta(path_pin) if (meta_pin$api_version == 0) { + print("0") path <- board_pin_get(board, name, ...) meta <- pin_registry_retrieve(board, name) meta$file <- setdiff(fs::path_rel(fs::dir_ls(path), path), "data.txt") @@ -159,6 +161,8 @@ pin_meta.pins_board_local <- function(board, name, version = NULL, ...) { local_meta(meta, dir = path, version = NULL) } else { + print("1") + print(meta_pin$versions) version <- version %||% last(meta_pin$versions) %||% abort("No versions found") path_version <- fs::path(board$path, name, version) From 3eeac8598be5a09889bcc2de54e4078212f81c66 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 29 Apr 2021 16:03:38 -0500 Subject: [PATCH 4/8] Only list directories containing data.txt --- R/board_local.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/board_local.R b/R/board_local.R index 2b3e3131a..6b93775a7 100644 --- a/R/board_local.R +++ b/R/board_local.R @@ -58,7 +58,10 @@ board_browse.pins_board_local <- function(board, ...) { #' @export pin_list.pins_board_local <- function(board, ...) { - fs::path_file(fs::dir_ls(board$path, type = "directory")) + dir <- fs::dir_ls(board$path, type = "directory") + metadata <- fs::path(dir, "data.txt") + + fs::path_file(dir[fs::file_exists(metadata)]) } #' @export From d2e7459518fbfa7d3a98ae17ee148e44eb3717fc Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 29 Apr 2021 16:09:25 -0500 Subject: [PATCH 5/8] Revert debugging code --- .github/workflows/R-CMD-check.yaml | 6 +++--- R/board_local.R | 4 ---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index cd637a355..7c181ad2c 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -23,9 +23,9 @@ jobs: matrix: config: - {os: windows-latest, r: 'release'} - # - {os: macOS-latest, r: 'release'} - # - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - # - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: macOS-latest, r: 'release'} + - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} env: R_REMOTES_NO_ERRORS_FROM_WARNINGS: true diff --git a/R/board_local.R b/R/board_local.R index 6b93775a7..14bea0ca3 100644 --- a/R/board_local.R +++ b/R/board_local.R @@ -146,7 +146,6 @@ pin_store.pins_board_local <- function(board, name, path, metadata, #' @export pin_meta.pins_board_local <- function(board, name, version = NULL, ...) { - print(name) check_name(name) path_pin <- fs::path(board$path, name) if (!fs::dir_exists(path_pin)) { @@ -156,7 +155,6 @@ pin_meta.pins_board_local <- function(board, name, version = NULL, ...) { # Fallback to old structure meta_pin <- read_meta(path_pin) if (meta_pin$api_version == 0) { - print("0") path <- board_pin_get(board, name, ...) meta <- pin_registry_retrieve(board, name) meta$file <- setdiff(fs::path_rel(fs::dir_ls(path), path), "data.txt") @@ -164,8 +162,6 @@ pin_meta.pins_board_local <- function(board, name, version = NULL, ...) { local_meta(meta, dir = path, version = NULL) } else { - print("1") - print(meta_pin$versions) version <- version %||% last(meta_pin$versions) %||% abort("No versions found") path_version <- fs::path(board$path, name, version) From 079ffacecdf50b308debbd2b03027eddbb5ecd8d Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 29 Apr 2021 16:09:49 -0500 Subject: [PATCH 6/8] Add _pkgdown.yml to .Rbuildignore --- .Rbuildignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.Rbuildignore b/.Rbuildignore index 743c0ca0b..20c9bceb6 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,3 +10,4 @@ ^vignettes/articles$ ^LICENSE\.md$ ^blog$ +^_pkgdown\.yml$ From a41abf309d819958a2f5b4b13155c3de7073dba0 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 30 Apr 2021 10:36:48 -0500 Subject: [PATCH 7/8] Translate encoding on write --- R/board_datatxt.R | 4 ++-- R/board_github.R | 2 +- R/board_rsconnect.R | 2 +- R/board_rsconnect_bundle.R | 2 +- R/meta.R | 2 +- R/pin_manifest.R | 4 ++-- R/pin_registry.R | 2 +- R/utils.R | 20 ++++++++++++++++++++ tests/testthat/test-utils.R | 13 +++++++++++++ 9 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 tests/testthat/test-utils.R diff --git a/R/board_datatxt.R b/R/board_datatxt.R index ac0a0e734..78655c590 100644 --- a/R/board_datatxt.R +++ b/R/board_datatxt.R @@ -108,7 +108,7 @@ datatxt_refresh_index <- function(board) { } fs::dir_create(fs::path_dir(local_index)) - yaml::write_yaml(current_index, local_index) + write_yaml(current_index, local_index) } @@ -527,7 +527,7 @@ board_manifest_load <- function(manifest) { } board_manifest_create <- function(index, file) { - yaml::write_yaml(index, file) + write_yaml(index, file) } pin_entries_to_dataframe <- function(entries) { diff --git a/R/board_github.R b/R/board_github.R index 594cfeac3..06a21ad2e 100644 --- a/R/board_github.R +++ b/R/board_github.R @@ -461,7 +461,7 @@ board_pin_create.pins_board_github <- function(board, path, name, metadata, ...) names(datatxt$filenames) <- datatxt$path - yaml::write_yaml(datatxt, file_path) + write_yaml(datatxt, file_path) } # create upload definition of remote-path/local-path diff --git a/R/board_rsconnect.R b/R/board_rsconnect.R index 836217459..4565d06f7 100644 --- a/R/board_rsconnect.R +++ b/R/board_rsconnect.R @@ -539,7 +539,7 @@ read_cache <- function(path) { update_cache <- function(path, key, value) { cache <- read_cache(path) cache[[key]] <- value - yaml::write_yaml(cache, path) + write_yaml(cache, path) value } diff --git a/R/board_rsconnect_bundle.R b/R/board_rsconnect_bundle.R index 89cea9e3b..8cf7af775 100644 --- a/R/board_rsconnect_bundle.R +++ b/R/board_rsconnect_bundle.R @@ -6,7 +6,7 @@ rsc_bundle <- function(board, name, path, metadata, x = NULL, bundle_path = temp fs::file_copy(path, fs::path(bundle_path, fs::path_file(path))) # * data.txt (used to retrieve pins) - yaml::write_yaml(metadata, fs::path(bundle_path, "data.txt")) + write_yaml(metadata, fs::path(bundle_path, "data.txt")) # * index.html rsc_bundle_preview_create(board, name, metadata, path = bundle_path, x = x) diff --git a/R/meta.R b/R/meta.R index 3c8e7b22f..c72590487 100644 --- a/R/meta.R +++ b/R/meta.R @@ -22,7 +22,7 @@ read_meta <- function(path) { write_meta <- function(x, path) { path <- fs::path(path, "data.txt") - yaml::write_yaml(x, path) + write_yaml(x, path) } # pin metadata ------------------------------------------------------------ diff --git a/R/pin_manifest.R b/R/pin_manifest.R index c7a7314df..d8abef409 100644 --- a/R/pin_manifest.R +++ b/R/pin_manifest.R @@ -16,7 +16,7 @@ pin_manifest_get <- function(path) { pin_manifest_update <- function(path, manifest) { data_txt <- file.path(path, "data.txt") - manifest <- yaml::write_yaml(manifest, data_txt) + manifest <- write_yaml(manifest, data_txt) manifest } @@ -33,7 +33,7 @@ pin_manifest_create <- function(path, metadata, files) { entries[sapply(entries, is.null)] <- NULL fs::dir_create(path) - yaml::write_yaml(entries, file.path(path, "data.txt")) + write_yaml(entries, file.path(path, "data.txt")) } # retrieve a list of files to download diff --git a/R/pin_registry.R b/R/pin_registry.R index 851207bb2..2b1787a56 100644 --- a/R/pin_registry.R +++ b/R/pin_registry.R @@ -18,7 +18,7 @@ pin_registry_read <- function(board) { pin_registry_write <- function(board, entries) { stopifnot(is.board(board)) - yaml::write_yaml(unname(entries), pin_registry_path(board, "data.txt")) + write_yaml(unname(entries), pin_registry_path(board, "data.txt")) } # Lock registry file to prevent multi-process race conditions diff --git a/R/utils.R b/R/utils.R index f1eb4897f..3ff2cd614 100644 --- a/R/utils.R +++ b/R/utils.R @@ -66,3 +66,23 @@ ui_loud <- function() { } github_raw <- function(x) paste0("https://raw.githubusercontent.com/", x) + +write_yaml <- function(x, path) { + x <- to_utf8(x) + yaml::write_yaml(x, path) +} + +# On Windows, yaml::write_yaml() crashes with Latin1 data +# https://github.com/viking/r-yaml/issues/90 +to_utf8 <- function(x) { + if (is.list(x)) { + if (!is.null(names(x))) { + names(x) <- enc2utf8(names(x)) + } + lapply(x, to_utf8) + } else if (is.character(x)) { + enc2utf8(x) + } else { + x + } +} diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R new file mode 100644 index 000000000..e71a8cd78 --- /dev/null +++ b/tests/testthat/test-utils.R @@ -0,0 +1,13 @@ +test_that("write_yaml can write non-UTF8 data", { + str <- "fa\xE7ile" + Encoding(str) <- "latin1" + + x <- list(str) + names(x) <- str + + path <- tempfile() + write_yaml(x, path) + + y <- yaml::read_yaml(path) + expect_equal(y, list("fa\u00e7ile" = "fa\u00e7ile")) +}) From 29bc87b2c7a0e760aa1fca05963b18f1b4247f13 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Fri, 30 Apr 2021 10:37:28 -0500 Subject: [PATCH 8/8] Restore original action --- .github/workflows/R-CMD-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 7c181ad2c..ddbd6ba5e 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -81,7 +81,7 @@ jobs: - name: Check env: _R_CHECK_CRAN_INCOMING_REMOTE_: false - run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), build_args = "--no-build-vignettes", error_on = "warning", check_dir = "check") + run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") shell: Rscript {0} - name: Upload check results