# The try-catch is here because the cluster's R image lacks git.
repo_name <- "unknown"
tryCatch({
        repo_name <- system("git config --get remote.origin.url", intern = TRUE)
}, error = function(x) {}
)

# The R on the cluster is also an older version that won't
# execute rampdata::data_configuration() in the preamble above.
# You can define it yourself, if that's the case.
params2 = list(data_config = rampdata::data_configuration())

From r repo_name on r date(), generated by r Sys.info()[["effective_user"]].

Overview

This notebook demonstrates the rampdata package. It defines the data configuration in a header. This data configuration can then help find data within code.

cat(params$data_config$LOCALDATA)

Local Path

The local_path command translates a keyword list into a path that's relative to the data directory on your computer.

shapefile <- list(location = "uganda", stage = "input", path = "UBOS/outline.shp")
rampdata::local_path(shapefile, params$data_config)
edited_shapefile <- list(stage = "working", path = "UBOS/outline_fixed.shp",
                         project = "rampdata")
rampdata::local_path(edited_shapefile, params$data_config)

Data configuration

That local path uses a configuration object that's initialized in the metadata section of this notebook.

params:
  data_config: !r rampdata::data_configuration()

When the notebook is built, R runs the data_configuration function in order to find the location of the data on your machine. It reads this configuration information from a data.ini file. Look at the help for data_configuration for an example of the data.ini and what to put in it.

We use the params because it is a portable way to set parameters. For instance, if you want to render a document from the command line, you can set them from there. ```{bash, eval = FALSE} R -e "rmarkdown::render('ramp_example.Rmd', params = list(data_config = '.'))"

This method works for running single functions, too,
so instead of running a script, we run a function from the package, through R.
```{bash, eval = FALSE}
R -e "gisdemog::generate_population()"


dd-harp/rampdata documentation built on Sept. 13, 2021, 9:32 p.m.