R code in package vignette cannot run on CRAN for security reasons. How to manage such vignette?
Asked Answered
R

2

9

An R package communicates with a commercial data base using a private user_name and password to establish connection. In the package_vignette.Rmd file there is a chunk of code:

```{r, eval = TRUE}
# set user_name and password from user's configuration file
set_connection(file = "/home/user001/connection.config")

# ask data base for all metrics it has
my_data <- get_all_metrics()

# display names of fetched metrics
head(my_data$name)
```

I do not have the rights to provide actual user_name and password to CRAN, so I can not supply genuine 'connection.config' file with the package. So, of course, this code fragment leads to Error during CRAN checks.

I know two ways to get around CRAN check:

  1. Use knitr option: eval = FALSE.

  2. Make static vignette with help of the R.rsp package.

The first way is too time-consuming, because there are a lot of chunks, and I rewrite/rebuild the vignette often. The second way is better for me. But may be there is a better pattern how to support such vignette? For example, in the package's tests I use testthat::skip_on_cran() to avoid CRAN checks.

Reshape answered 14/4, 2015 at 15:20 Comment(2)
include sample data in your package, e.g. fetch_sample_all_metrics(), with non sensitive/anonymized data, and use it in your vignetteClaiborne
You can set all chunks to eval=F by calling knitr::opts_chunk$set(eval=F) inside the first chunk.Taught
C
2

The easiest way is just to include the data with your package. Either the dummy data set in:

  • the data directory. This would allow users to easily access it.
  • or in inst/extdata. Users can can access this file, but it's a bit more hidden. You would find the location using system.file(package="my_pkg")

In the vignette you would have something

```{r, echo=FALSE}
data(example_data, package="my_pkg")
my_data = example_data
```

```{r, eval = FALSE}
# set user_name and password from user's configuration file
set_connection(file = "/home/user001/connection.config")

# ask data base for all metrics it has
my_data <- get_all_metrics()
```
Cancellation answered 18/9, 2016 at 9:51 Comment(0)
B
1

testthat::skip_on_cran just checks a system variable

> testthat::skip_on_cran
function () 
{
    if (identical(Sys.getenv("NOT_CRAN"), "true")) {
        return(invisible(TRUE))
    }
    skip("On CRAN")
}
<environment: namespace:testthat>

From what I gather, this is set by testthat or devtools. Thus, you could use

eval = identical(Sys.getenv("NOT_CRAN"), "true")

in the chunk option and load testthat or devtools in one of the first chunks. Otherwise, you can use a similar mechanism on your site and assign a similar system variable and check if it is "true". E.g., use Sys.setenv("IS_MY_COMP", "true")). Then put a Sys.setenv call in your .Rprofile file if you use R studio or in your R_HOME/Rprofile.site file. See help("Startup") for information on the later option.

Alternatively, you can check if "/home/user001/connection.config" exists with

eval = file.exists("/home/user001/connection.config")

in the chunk option.

Bermuda answered 25/11, 2017 at 8:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.