How to consider custom arguments of a package while building vignette? - r

I have a package which requires some custom arguments for installation. I can use R CMD INSTALL ---configure-args=... pkg.tar.gz to install the package successfully. I can also use R CMD check --install-args=configure-args=... to check the package after getting the custom arguments.
However, R CMD build doesn't have any arguments like --install-args and/or configure-args and R CMD build is used for building vignettes. I want to get the output of my R code chunks included in the vignette to its html output file and include it in the package source. Is there any way possible to build vignette with --configure-args or is there any workaround to produce the desired html vignette and include it in the package source?
Looking forward to your suggestions.

As you say, when R CMD build rebuilds your vignettes, it doesn't include a way to specify --include-args, so the temporary install needs to work with default settings.
There are two ways to achieve this. You could specify --no-build-vignettes. This would require that you have already put the built vignettes into the inst/doc directory, and R CMD build will just use what's there.
The other way is to make sure that on your machine the default configuration works. If you need to build on several different machines, this could be achieved by having your build script look at environment variables to find default settings if corresponding configure arguments aren't given. Then on each machine you specify the environment variables for R CMD build to see, e.g.
DEFAULT_LOCATION="/some/dir" R CMD build yourpackage

Related

R -- What exactly does install_github do?

never used R before. I need to integrate R into continuous build.
The script I got has the line
RUN Rscript -e "devtools::install_github('my-repo', auth_token = '"$Github_Token"')"
I know this command will download the entire repo, but how is the package installed? Is it looking for the .R files, or is it looking for the .rba files?
My goal is to integrate a build process with a CI. I found a way to construct these rba files through a docker container, but these will not be checked into github. I need to make sure the install doesn't require these rba files, then I can move these files somewhere else.
The function install_github installs a package the same as any other method of package installation, but automates the download from github for you. The remote repository needs to be an R package, meaning it needs to have at least an R/ directory containing R code, a DESCRIPTION file containing the package metadata, and a NAMESPACE file describing the package imports and exports.
For install_github to work, it should not inherently require that your rba files are present.
For more information on packages, I suggest reading R packages.

How can I test a change on a forked R package before sending a pull request?

I have forked and cloned an R repository on my local computer. I have made some edits but I'm not sure how to test these changes before sending out a pull request.
I don't know how to make an R package from this clone one and test it.
The usual two-step:
R CMD build directoryOfYourPackage
resulting in a tar.gz archive you use in the next step:
R CMD check package_1.2.3.tar.gz
where package and the version are determined by the DESCRIPTION file.
Both commands have options, i.e. you can suppress vignette creation and test if you have an insufficient LaTeX installation and these pdf vignettes etc pp. See Writing R Extensions for all the gory details.
Also, if you are set up for Travis CI and the package is then your commit back to your fork should trigger a build at Travis doing the same: package building and check. However, it is also a good idea to check locally before committing...

R CMD check does not respect selective code evaluation in knitr code chunks

I am building a package in R 3.1.0 on Windows 7 32-bit (and also on a different machine running Windows 8 64bit) and I am using knitr to write vignettes using Markdown. I am hoping to publish this package on CRAN so I am using R CMD check to check that my demos, datasets and vignettes all behave properly. I keep my vignettes as .Rmd files (rather than making them outside of the package building process and stashing them in inst/doc) because they serve as extra tests on my package and aren't very big anyway.
My problem is that R CMD check fails when building my vignettes, even though if I run R CMD build and then R CMD INSTALL --build everything works out fine. Looking at the log file, it appears to be failing because it tries to evaluate code that I have explicitly told knitr NOT to evaluate. As a generic example, if I write
```{r example-chunk eval=c(1:3, 5:6), tidy=FALSE}
foo = 5
bar = 3
## don't evaluate the next line
file.show("i/dont/really/exist.csv")
## ok, start evaluating again
foobar = foo*bar
```
In a .Rmd file, running R CMD check will fail because it will try to evaluate line 4. However, the chunk will be correctly evaluated if I run R CMD build mypackage and then R CMD install --build mypackage.tar.gz (I know this because I can go to my Rlibs folder and find the flawless html vignettes in mypackage/doc. Similarly, the chunk will also be evaluated correctly I if run R CMD Sweave to build the vignette.
If you want to try this yourself, the package I am building (where I am running into the issue) is on Github: https://github.com/mkoohafkan/flowdurr-edu. You can look at raw/packagemaker.html for instructions, hopefully it's straightforward (the R code runs through the process of making the package directory, building the help files and copying some manually edited files into the package directory). R CMD check fails on all of my vignettes: when building flowdurr-datasets.Rmd, it insists on evaluating a line with a fake path even though I told it not to. When building hspf-analysis.Rmd, R CMD check insists on evaluating a line I excluded because it takes a really long time to complete (using rgenoud to fit some distribution parameters). R CMD check also fails on vignette.Rmd, but for a different reason; I purposely throw errors to show examples of what you can't do with a particular function, and while knitr doesn't have a problem with it R CMD check sure does!
EDIT: My build script was getting some hate so I made this dummy package that reproduced the problem on both of my machines. It illustrates that 1) R CMD check evaluates a line that it shouldn't, and 2) R CMD check does not support error evaluation in a vignette, even though knitr will write error output without issue.
So I guess my question is: What is it that R CMD check is doing differently from R CMD Sweave and R CMD build/install when it comes to vignette building, and is there anything I can do to make R CMD check respect knitr's 'eval' specification? Note that if I use eval=FALSE, R CMD check will respect it and everything is fine; the problem only occurs if I try selective evaluation of a chunk.
I have added vignette engines with the suffix _notangle in the knitr development version 1.6.2. For the original vignette engine knitr::foo, you can use the new engine knitr::foo_notangle to disable tangle (e.g. knitr::knitr_notangle, knitr::rmarkdown_notangle, ...).
If you do not want to wait for the next version of knitr to be on CRAN (which might take a while), you can certainly register a package vignette engine by yourself. Hint: you can make use of existing engines in tools::vignetteEngine(package = 'knitr') so you do not have to completely redefine the knitr vignette engines.
It seems that the issue is more nuanced than I originally thought, so this might not get resolved anytime soon. my workaround is to:
manually build the vignettes using R CMD Sweave
Copy the HTML outputs to inst/doc
Delete the vignettes folder (or add entries to .Rbuildignore--thanks #Ben!)
Build and check
It's not ideal, but right now it looks like the only way for my package to get through CRAN checks.

Utility for checking source file(s) for errors

When developing a package one can run R CMD check, which helpfully tells you any problems in your code (syntax errors, unstated dependencies, undefined variables).
Does a utility exist that will provide this functionality of R CMD check for individual source files?
I could create an empty package and move source files in their to check them, but that's both a pain, and overkill.
It sounds like you want to look at the codetools package.

Package dependencies for R CMD check

The DESCRIPTION file in R packages has several ways of specifying dependencies, e.g. Depends, Suggests and Imports. Which one should I use to specify a dependency that is optional once the package is installed, but required for running R CMD check?
In my particular case I am using testthat to run some tests automatically when R CMD check is run, but during "normal" operation, testthat is not required. The answer to this question suggests that testthat should be in Suggests, but is that enough to ensure that R CMD check runs correctly?
What I would like to see, if it exists, is a field where I can speciy dependencies that are required only to run R CMD check, which should fail with an appropriate error message if these packages are not available.
Yes, you should put them in the Suggests field. The only other thing required for R CMD check to run successfully is to ensure the packages in the Suggests field are installed in a location that will be found by R CMD check.
If they're not available, you can set the environment variable _R_CHECK_FORCE_SUGGESTS=false and R CMD check will run, with a "NOTE" about the missing suggested packages.

Resources