Skip to content

Commit

Permalink
Merge pull request #131 from ropensci/document
Browse files Browse the repository at this point in the history
Set install = FALSE by default for document()
  • Loading branch information
slager committed Apr 24, 2024
2 parents b06f8c6 + 41ca4eb commit debcbb8
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 53 deletions.
6 changes: 3 additions & 3 deletions R/processData.R
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ project_data_path <- function(file = NULL) {
#' @rdname document
#' @title Build documentation for a data package using DataPackageR.
#' @param path \code{character} the path to the data package source root.
#' @param install \code{logical} install and reload the package. (default TRUE)
#' @param install \code{logical} install the package. (default FALSE)
#' @param ... additional arguments to \code{install}
#' @returns Called for side effects. Returns TRUE on successful exit.
#' @export
Expand Down Expand Up @@ -745,10 +745,10 @@ project_data_path <- function(file = NULL) {
#' # call package_build to run the "foo.Rmd" processing and
#' # build a data package.
#' package_build(file.path(tempdir(), pname), install = FALSE)
#' document(path = file.path(tempdir(), pname), install=FALSE)
#' document(path = file.path(tempdir(), pname), install = FALSE)
#' }
#' }
document <- function(path = ".", install = TRUE, ...) {
document <- function(path = ".", install = FALSE, ...) {
if (getOption('DataPackageR_verbose', TRUE)) cat("\n")
usethis::proj_set(path = path)
path <- usethis::proj_get()
Expand Down
19 changes: 10 additions & 9 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -196,29 +196,30 @@ datapackage_skeleton(
# These will be added to the NEWS.md file along with the DataVersion in the package source directory.
# If the build is run in non-interactive mode, the description will read
# "Package built in non-interactive mode". You may update it later.
dir.create(file.path(tempdir(),"lib"))
package_build(packageName = file.path(tempdir(),"mtcars20"), install = FALSE,
lib = file.path(tempdir(),"lib"))
package_build(packageName = file.path(tempdir(),"mtcars20"))
# Update the autogenerated roxygen documentation in data-raw/documentation.R.
# edit(file.path(tempdir(),"mtcars20","R","mtcars20.R"))
# 4. Rebuild the documentation.
document(file.path(tempdir(),"mtcars20"), install = FALSE,
lib = file.path(tempdir(),"lib"))
document(file.path(tempdir(),"mtcars20"))
# Let's use the package we just created.
install.packages(file.path(tempdir(),"mtcars20_1.0.tar.gz"), type = "source", repos = NULL)
library(mtcars20)
# During actual use, the temporary library does not need to be specified.
temp_lib <- file.path(tempdir(),"lib")
dir.create(temp_lib)
install.packages(file.path(tempdir(),"mtcars20_1.0.tar.gz"),
type = "source", repos = NULL, lib = temp_lib)
library(mtcars20, lib.loc = temp_lib)
data("cars_over_20") # load the data
cars_over_20 # Now we can use it.
?cars_over_20 # See the documentation you wrote in data-raw/documentation.R.
# We have our dataset!
# Since we preprocessed it,
# it is clean and under the 5 MB limit for data in packages.
cars_over_20
?cars_over_20 # See the documentation you wrote in data-raw/documentation.R.
# We can easily check the version of the data
data_version("mtcars20")
Expand Down
41 changes: 16 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ datapackage_skeleton(
code_files = processing_code,
r_object_names = "cars_over_20",
path = tempdir())
#> ✔ Creating 'C:/Users/dslager/AppData/Local/Temp/RtmpSCRvVa/mtcars20/'
#> ✔ Setting active project to 'C:/Users/dslager/AppData/Local/Temp/RtmpSCRvVa/mtcars20'
#> ✔ Creating 'C:/Users/dslager/AppData/Local/Temp/RtmpuqBumR/mtcars20/'
#> ✔ Setting active project to 'C:/Users/dslager/AppData/Local/Temp/RtmpuqBumR/mtcars20'
#> ✔ Creating 'R/'
#> ✔ Writing 'DESCRIPTION'
#> Package: mtcars20
Expand All @@ -251,7 +251,7 @@ datapackage_skeleton(
#> RoxygenNote: 7.3.1
#> ✔ Writing 'NAMESPACE'
#> ✔ Setting active project to '<no active project>'
#> ✔ Setting active project to 'C:/Users/dslager/AppData/Local/Temp/RtmpSCRvVa/mtcars20'
#> ✔ Setting active project to 'C:/Users/dslager/AppData/Local/Temp/RtmpuqBumR/mtcars20'
#> ✔ Added DataVersion string to 'DESCRIPTION'
#> ✔ Creating 'data-raw/'
#> ✔ Creating 'data/'
Expand All @@ -266,9 +266,7 @@ datapackage_skeleton(
# These will be added to the NEWS.md file along with the DataVersion in the package source directory.
# If the build is run in non-interactive mode, the description will read
# "Package built in non-interactive mode". You may update it later.
dir.create(file.path(tempdir(),"lib"))
package_build(packageName = file.path(tempdir(),"mtcars20"), install = FALSE,
lib = file.path(tempdir(),"lib"))
package_build(packageName = file.path(tempdir(),"mtcars20"))
#>
#> ✔ 1 data set(s) created by subsetCars.Rmd
#> • cars_over_20
Expand All @@ -281,13 +279,13 @@ package_build(packageName = file.path(tempdir(),"mtcars20"), install = FALSE,
#> Writing 'mtcars20.Rd'
#> Writing 'cars_over_20.Rd'
#> ── R CMD build ─────────────────────────────────────────────────────────────────
#> checking for file 'C:\Users\dslager\AppData\Local\Temp\RtmpSCRvVa\mtcars20/DESCRIPTION' ... ✔ checking for file 'C:\Users\dslager\AppData\Local\Temp\RtmpSCRvVa\mtcars20/DESCRIPTION'
#> checking for file 'C:\Users\dslager\AppData\Local\Temp\RtmpuqBumR\mtcars20/DESCRIPTION' ... ✔ checking for file 'C:\Users\dslager\AppData\Local\Temp\RtmpuqBumR\mtcars20/DESCRIPTION' (341ms)
#> ─ preparing 'mtcars20':
#> checking DESCRIPTION meta-information ... checking DESCRIPTION meta-information ... ✔ checking DESCRIPTION meta-information
#> ─ checking for LF line-endings in source and make files and shell scripts
#> ─ checking for empty or unneeded directories
#> ─ looking to see if a 'data/datalist' file should be added
#> ─ building 'mtcars20_1.0.tar.gz'
#> ─ building 'mtcars20_1.0.tar.gz'
#>
#> Next Steps
#> 1. Update your package documentation.
Expand All @@ -300,34 +298,25 @@ package_build(packageName = file.path(tempdir(),"mtcars20"), install = FALSE,
#> - Set up a github repository for your pacakge.
#> - Add the github repository as a remote of your local package repository.
#> - git push your local repository to gitub.
#> [1] "C:/Users/dslager/AppData/Local/Temp/RtmpSCRvVa/mtcars20_1.0.tar.gz"
#> [1] "C:/Users/dslager/AppData/Local/Temp/RtmpuqBumR/mtcars20_1.0.tar.gz"

# Update the autogenerated roxygen documentation in data-raw/documentation.R.
# edit(file.path(tempdir(),"mtcars20","R","mtcars20.R"))

# 4. Rebuild the documentation.
document(file.path(tempdir(),"mtcars20"), install = FALSE,
lib = file.path(tempdir(),"lib"))
document(file.path(tempdir(),"mtcars20"))
#> ℹ Updating mtcars20 documentation
#> ℹ Loading mtcars20
#> [1] TRUE

# Let's use the package we just created.
install.packages(file.path(tempdir(),"mtcars20_1.0.tar.gz"), type = "source", repos = NULL)
#> Installing package into 'C:/Users/dslager/AppData/Local/Temp/Rtmpk5QUs0/temp_libpath1af01866231b'
#> (as 'lib' is unspecified)
library(mtcars20)
# During actual use, the temporary library does not need to be specified.
temp_lib <- file.path(tempdir(),"lib")
dir.create(temp_lib)
install.packages(file.path(tempdir(),"mtcars20_1.0.tar.gz"),
type = "source", repos = NULL, lib = temp_lib)
library(mtcars20, lib.loc = temp_lib)
data("cars_over_20") # load the data
cars_over_20 # Now we can use it.
#> speed dist
#> 44 22 66
#> 45 23 54
#> 46 24 70
#> 47 24 92
#> 48 24 93
#> 49 24 120
#> 50 25 85
?cars_over_20 # See the documentation you wrote in data-raw/documentation.R.

# We have our dataset!
# Since we preprocessed it,
Expand All @@ -342,6 +331,8 @@ cars_over_20
#> 49 24 120
#> 50 25 85

?cars_over_20 # See the documentation you wrote in data-raw/documentation.R.

# We can easily check the version of the data
data_version("mtcars20")
#> [1] '0.1.0'
Expand Down
6 changes: 3 additions & 3 deletions man/document.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat/test-document.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ NULL
close(connection)
expect_true(
document(file.path(tempdir, "subsetCars"),
install = TRUE,
lib = temp_libpath,
quiet = ! getOption('DataPackageR_verbose', TRUE))
)
Expand Down
20 changes: 8 additions & 12 deletions vignettes/Using_DataPackageR.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: "Using DataPackageR"
author: "Greg Finak <gfinak@fredhutch.org>"
date: "`r Sys.Date()`"
output:
rmarkdown::html_vignette:
Expand Down Expand Up @@ -153,13 +152,7 @@ This will be converted to an Rmd file with a proper yaml header, which will then
Once the skeleton framework is set up, run the preprocessing code to build `cars_over_20`, and reproducibly enclose it in a package.

```{r , eval = rmarkdown::pandoc_available()}
dir.create(file.path(tempdir(),"lib"))
DataPackageR:::package_build(
file.path(tempdir(),"mtcars20"),
install = TRUE,
lib = file.path(tempdir(),"lib")
)
DataPackageR::package_build(file.path(tempdir(),"mtcars20"))
```

### Documenting your data set changes in NEWS.
Expand Down Expand Up @@ -216,8 +209,7 @@ The autogenerated documentation source is in the `documentation.R` file in `data
You should update this file to properly document your objects. Then rebuild the documentation:

```{r rebuild_docs, eval = rmarkdown::pandoc_available()}
dir.create(file.path(tempdir(),"lib")) # a temporary library directory
document(file.path(tempdir(),"mtcars20"), lib = file.path(tempdir(),"lib"))
DataPackageR::document(file.path(tempdir(),"mtcars20"))
```

Updating documentation does not reprocess the data.
Expand All @@ -244,8 +236,12 @@ The data set documentation will be accessible via `?cars_over_20`, and the data
# Create a temporary library to install into.
dir.create(file.path(tempdir(),"lib"))
# Let's use the package we just created.
install.packages(file.path(tempdir(),"mtcars20_1.0.tar.gz"), type = "source", repos = NULL, lib = file.path(tempdir(),"lib"))
# Let's install the package we just created.
# This can also be done with with `install = TRUE` in package_build() or document().
install.packages(file.path(tempdir(),"mtcars20_1.0.tar.gz"),
type = "source", repos = NULL,
lib = file.path(tempdir(),"lib"))
lns <- loadNamespace
if (!"package:mtcars20"%in%search())
attachNamespace(lns('mtcars20',lib.loc = file.path(tempdir(),"lib"))) #use library() in your code
Expand Down
1 change: 0 additions & 1 deletion vignettes/YAML_Configuration_Details.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
title: "YAML Configuration Details"
author: "Greg Finak <gfinak@fredhutch.org>"
date: "`r Sys.Date()`"
output:
rmarkdown::html_vignette:
Expand Down

0 comments on commit debcbb8

Please sign in to comment.