Skip to content

Commit

Permalink
Set LazyData when adding data (r-lib#1404)
Browse files Browse the repository at this point in the history
To match new CRAN check. Fixes r-lib#1403.
  • Loading branch information
malcolmbarrett authored Apr 13, 2021
1 parent 39410e1 commit 753f04d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

* Added `use_import_from()` to put `@importFrom pkg fun` into a package in a
consistent way (@malcolmbarrett, #1377)

* `DESCRIPTION` files generated by usethis no longer include `LazyData` by
default per new CRAN checks; instead, `LazyData` is now added the first time
you use `use_data()` (@malcolmbarrett, #1404)

# usethis 2.0.1

Expand Down
5 changes: 5 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ use_data <- function(...,
} else {
use_directory("data")
paths <- path("data", objs, ext = "rda")
if (!desc::desc_has_fields("LazyData")) {
ui_done("Setting {ui_field('LazyData')} to \\
{ui_value('true')} in {ui_path('DESCRIPTION')}")
desc::desc_set("LazyData", "true")
}
}
check_files_absent(proj_path(paths), overwrite = overwrite)

Expand Down
3 changes: 1 addition & 2 deletions R/description.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ use_description_defaults <- function(package = NULL,
Description = "What the package does (one paragraph).",
"Authors@R" = 'person("First", "Last", , "[email protected]", c("aut", "cre"), comment = c(ORCID = "YOUR-ORCID-ID"))',
License = "`use_mit_license()`, `use_gpl3_license()` or friends to pick a license",
Encoding = "UTF-8",
LazyData = "true"
Encoding = "UTF-8"
)

if (roxygen) {
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ library(usethis)
# Create a new package -------------------------------------------------
path <- file.path(tempdir(), "mypkg")
create_package(path)
#> βœ“ Creating '/tmp/RtmpBtK0Bx/mypkg/'
#> βœ“ Setting active project to '/private/tmp/RtmpBtK0Bx/mypkg'
#> βœ“ Creating '/var/folders/03/9x7925g54mncswxx06wpkxl00000gn/T/RtmpxLZ8U3/mypkg/'
#> βœ“ Setting active project to '/private/var/folders/03/9x7925g54mncswxx06wpkxl00000gn/T/RtmpxLZ8U3/mypkg'
#> βœ“ Creating 'R/'
#> βœ“ Writing 'DESCRIPTION'
#> Package: mypkg
Expand All @@ -73,15 +73,14 @@ create_package(path)
#> License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
#> license
#> Encoding: UTF-8
#> LazyData: true
#> Roxygen: list(markdown = TRUE)
#> RoxygenNote: 7.1.1
#> βœ“ Writing 'NAMESPACE'
#> βœ“ Setting active project to '<no active project>'
# only needed since this session isn't interactive
proj_activate(path)
#> βœ“ Setting active project to '/private/tmp/RtmpBtK0Bx/mypkg'
#> βœ“ Changing working directory to '/tmp/RtmpBtK0Bx/mypkg/'
#> βœ“ Setting active project to '/private/var/folders/03/9x7925g54mncswxx06wpkxl00000gn/T/RtmpxLZ8U3/mypkg'
#> βœ“ Changing working directory to '/var/folders/03/9x7925g54mncswxx06wpkxl00000gn/T/RtmpxLZ8U3/mypkg/'

# Modify the description ----------------------------------------------
use_mit_license("My Name")
Expand Down Expand Up @@ -115,6 +114,7 @@ y <- 2
use_data(x, y)
#> βœ“ Adding 'R' to Depends field in DESCRIPTION
#> βœ“ Creating 'data/'
#> βœ“ Setting LazyData to 'true' in 'DESCRIPTION'
#> βœ“ Saving 'x', 'y' to 'data/x.rda', 'data/y.rda'
#> ● Document your data (see 'https://r-pkgs.org/data.html')

Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ test_that("use_data() stores new, non-internal data", {
pkg <- create_local_package()
letters2 <- letters
month.abb2 <- month.abb
expect_false(desc::desc_has_fields("LazyData"))
use_data(letters2, month.abb2)
expect_true(desc::desc_has_fields("LazyData"))
rm(letters2, month.abb2)

load(proj_path("data", "letters2.rda"))
Expand Down

0 comments on commit 753f04d

Please sign in to comment.