Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local scoping and local tempdirs for edge case test file #140

Merged
merged 2 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/DataPackageR-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' "inst/extdata" but large raw data files can be read from sources external
#' to the package source tree.
#'
#' Configuration is controlled via the config.yml file created at the package root.
#' Configuration is controlled via the datapackager.yml file created at the package root.
#' Its properties include a list of R and Rmd files that are to be rendered / sourced and
#' which read data and do the actual processing.
#' It also includes a list of r object names created by those files. These objects
Expand All @@ -33,7 +33,7 @@
#' Once the package is built and installed, the data objects created in the package are accessible via
#' the \code{data()} API, and
#' Calling \code{datapackage_skeleton()} and passing in R / Rmd file names, and r object names
#' constructs a skeleton data package source tree and an associated \code{config.yml} file.
#' constructs a skeleton data package source tree and an associated \code{datapackager.yml} file.
#'
#' Calling \code{package_build()} sets the build process in motion.
#' @examples
Expand Down
2 changes: 1 addition & 1 deletion R/environments.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' find_me <- datapackager_object_read("find_me") # This would appear in an Rmd processed by
#' # DataPackageR to access the object named "find_me" created
#' # by a previous script. "find_me" would also need to
#' # appear in the objects property of config.yml
#' # appear in the objects property of datapackager.yml
#' }
#' }
datapackager_object_read <- function(name) {
Expand Down
4 changes: 2 additions & 2 deletions inst/extdata/tests/extra.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ output: html_document
knitr::opts_chunk$set(echo = TRUE)
```

This file is processed second in the `config.yml` file. It therefore has access to the data objects
created by `subsetCars.Rmd`, the file that is processed first in the `config.yml`.
This file is processed second in the `datapackager.yml` file. It therefore has access to the data objects
created by `subsetCars.Rmd`, the file that is processed first in the `datapackager.yml`.

## Reading objects from previously run files

Expand Down
8 changes: 4 additions & 4 deletions inst/extdata/tests/subsetCars.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ knitr::opts_chunk$set(echo = TRUE)
This is a simple Rmd file that demonstrates how DataPackageR processes Rmarkdown files and creates data sets
that are then stored in an R data package.

In the `config.yml` for this example, this file is listed first, and therefore processed first.
In the `datapackager.yml` for this example, this file is listed first, and therefore processed first.

This particular document simply subsets the `cars` data set:

Expand All @@ -34,19 +34,19 @@ The data frame `cars_over_20` now holds this information.

When DataPackageR processes this file, it creates this `cars_over_20` object. After processing the file it does several things:

1. It compares the objects in the rmarkdown render environment of `subsetCars.Rmd` against the objects listed in the `config.yml` file `objects` property.
1. It compares the objects in the rmarkdown render environment of `subsetCars.Rmd` against the objects listed in the `datapackager.yml` file `objects` property.
2. It finds `cars_over_20` is listed there, so it stores it in a new environment.
3. That environment is passed to subsequent R and Rmd files. Specifically when the `extra.Rmd` file is processed, it has access to an environment object that holds all the `objects` (defined in the yaml config) that have already been created and processed. This environment is passed into subsequent scripts at the `render()` call.

All of the above is done automatically. The user only needs to list the objects to be stored and passed to other scripts in the `config.yml` file.
All of the above is done automatically. The user only needs to list the objects to be stored and passed to other scripts in the `datapackager.yml` file.

The `datapackager_object_read()` API can be used to retrieve these objects from the environment.

### Storing objects in the data package

In addition to passing around an environment to subsequent scripts, the `cars_over_20` object is stored in the data package `/data` directory as an `rda` file.

Note that this is all done automatically. The user does not need to explicitly save anything, they only need to list the objects to be store in the `config.yml`.
Note that this is all done automatically. The user does not need to explicitly save anything, they only need to list the objects to be store in the `datapackager.yml`.

This object is then accessible in the resulting package via the `data()` API, and its documentation is accessible via `?cars_over_20`.

Expand Down
8 changes: 4 additions & 4 deletions inst/extdata/tests/subsetCars.html
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ <h4 class="author"><em>Greg Finak</em></h4>


<p>This is a simple Rmd file that demonstrates how DataPackageR processes Rmarkdown files and creates data sets that are then stored in an R data package.</p>
<p>In the <code>config.yml</code> for this example, this file is listed first, and therefore processed first.</p>
<p>In the <code>datapackager.yml</code> for this example, this file is listed first, and therefore processed first.</p>
<p>This particular document simply subsets the <code>cars</code> data set:</p>
<pre class="r"><code>summary(cars)</code></pre>
<pre><code>## speed dist
Expand All @@ -333,16 +333,16 @@ <h4 class="author"><em>Greg Finak</em></h4>
<h1>Storing data set objects and making making accessible to other processing scripts.</h1>
<p>When DataPackageR processes this file, it creates this <code>cars_over_20</code> object. After processing the file it does several things:</p>
<ol style="list-style-type: decimal">
<li>It compares the objects in the rmarkdown render environment of <code>subsetCars.Rmd</code> against the objects listed in the <code>config.yml</code> file <code>objects</code> property.</li>
<li>It compares the objects in the rmarkdown render environment of <code>subsetCars.Rmd</code> against the objects listed in the <code>datapackager.yml</code> file <code>objects</code> property.</li>
<li>It finds <code>cars_over_20</code> is listed there, so it stores it in a new environment.</li>
<li>That environment is passed to subsequent R and Rmd files. Specifically when the <code>extra.Rmd</code> file is processed, it has access to an environment object that holds all the <code>objects</code> (defined in the yaml config) that have already been created and processed. This environment is passed into subsequent scripts at the <code>render()</code> call.</li>
</ol>
<p>All of the above is done automatically. The user only needs to list the objects to be stored and passed to other scripts in the <code>config.yml</code> file.</p>
<p>All of the above is done automatically. The user only needs to list the objects to be stored and passed to other scripts in the <code>datapackager.yml</code> file.</p>
<p>The <code>datapackager_object_read()</code> API can be used to retrieve these objects from the environment.</p>
<div id="storing-objects-in-the-data-package" class="section level3">
<h3>Storing objects in the data package</h3>
<p>In addition to passing around an environment to subsequent scripts, the <code>cars_over_20</code> object is stored in the data package <code>/data</code> directory as an <code>rda</code> file.</p>
<p>Note that this is all done automatically. The user does not need to explicitly save anything, they only need to list the objects to be store in the <code>config.yml</code>.</p>
<p>Note that this is all done automatically. The user does not need to explicitly save anything, they only need to list the objects to be store in the <code>datapackager.yml</code>.</p>
<p>This object is then accessible in the resulting package via the <code>data()</code> API, and its documentation is accessible via <code>?cars_over_20</code>.</p>
</div>
<div id="data-object-documentation" class="section level3">
Expand Down
4 changes: 2 additions & 2 deletions man/DataPackageR-package.Rd

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

2 changes: 1 addition & 1 deletion man/datapackager_object_read.Rd

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