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:
Use knitr option: eval = FALSE
.
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.
The easiest way is just to include the data with your package. Either the dummy data set in:
data
directory. This would allow users to easily access it. 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()
```
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With