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.
Related
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
For reasons that are too long to explain here, I must use R.2.8.1 (unfortunately). I need to have the xlsx package installed on it. Since I am on R 2.8.1, about ten years old, I can't use the latest version of xlsx but an older version, for instance xlsx_0.1.3 from 2010 seems a good choice. However the previous releases per R-CRAN policy are only available in tar.gz.
This is very unfortunate to me because I have to use RGui on windows which only accepts .Zip packages in installation. Therefore I tried the following stuff, in vain:
1-I tried to use Rcmd but I get the following error message:
C:\Program Files (x86)\R\R-2.8.1\bin>Rcmd INSTALL C:\Users\username\Downloads\xlsx_0.1.3.tar.gz
Can't use 'defined(#array)' (Maybe you should just omit the defined()?) at C:\PROGRA~2\R\R-28~1.1/bin/INSTALL line 42.
so I give up on this one.
2-Then I think that the best solution is to convert the package xlsx_0.1.3.tar.gz into a compatible xlsx_0.1.3.zip package by building it using R.2.8.1 but I can't make it. Here is one of the things I have tried so far.
I have unziped xlsx_0.1.3.tar.gz and I organized it in the following way, which brought me the furthest:
Documents\xlsx
Documents\xlsx\activate.bat
Documents\xlsx\build_xlsx.bat
Documents\xlsx\R
Documents\xlsx\R\inst
Documents\xlsx\R\man
Documents\xlsx\R\other
Documents\xlsx\R\R
Documents\xlsx\R\DESCRIPTION
Documents\xlsx\R\NAMESPACE
Documents\xlsx\R\NEWS
Documents\xlsx\R\WISHLIST
inside activate.bat, I wrote:
SET TMP=C:\Users\username\Documents\TOTO\xlsx\tmp
SET TEMP=%TMP%
SET RTOOLSPATH=C:\DEV_307\toto\Rtools
SET RPATH=C:\DEV\toto\R\R-2.8.1
SET PATH=%RTOOLSPATH%\bin;%RTOOLSPATH%\MinGW\bin;%RPATH%\bin;%PATH%
inside build_xlsx.bat, I wrote:
R CMD BUILD R
R CMD check --no-examples --no-tests R
R CMD build --docs=normal --binary R
Then I still get:
C:\Users\username\Documents\TOTO\xlsx>R CMD BUILD R
* checking for file 'R/DESCRIPTION' ... OK
* preparing 'R':
* checking DESCRIPTION meta-information ... OK
* installing the package to re-build vignettes
Can't use 'defined(#array)' (Maybe you should just omit the defined()?) at C:\DEV\toto\R\R-2.8.1/bin/INSTALL line 42.
ERROR
Installation failed.
Removing 'C:/Users/username/Documents/Rinst1210839349'
Thank you for your help
I can't include structured content in comments. This is really a comment.
The structure of source packages (which is what you have with xlsx_0.1.3.tar.gz if you pulled it from the CRAN archives) hasn't changed (much) since 2.8.1.
You'll also need to grab rJava_0.8-3.tar.gz and xlsxjars_0.2.0.tar.gz from the archive as xlsxjars + xlsx rely on rJava.
Extract each (since Windows R 2.8.1 seems to not grok gz files). They should make rJava, xlsxjars and xlsx directories each.
Move to the parent directory of both.
Run:
R CMD javareconf
R CMD build rJava
R CMD INSTALL rJava_0.8-3.zip # I believe this will be the name
R CMD build xlsxjars
R CMD INSTALL xlsxjars_0.2.0.zip
R CMD build xlsx
R CMD INSTALL xlsx_0.1.3.zip
and you should be gtg.
I am working on a package which I can load using devtools. But
R CMD check asm
gives me an error message
Error : package ‘seedDisp’ required by ‘asm’ could not be found
Which is kind of obvious as it is not installed in the global library.
But: I have installed installed in a local library (./library) and I have a .Rprofile file in the directory from which I run the checks as follow:
.libPaths(normalizePath("library"))
So when I run R and use devtools and load_all(.) it loads as the package seedDisp is installed.
It seems that R CMD check does ignore the library location which is set via the .Rprofile file.
So I tried
R CMD CHECK -l ./library asm_0.0.1.tar.gz
but it seems that -l only is used to install in and not to look for installed packages.
How can I tell R CMD check to look for installed packages in the library at ./library ?
One way to do this is via the R_LIBS_USER variable so I generally do
R_LIBS_USER=/some/other/path R CMD check asm_0.0.1.tar.gz
If that variable is generally set on your system, you need to do the usual trick of appending, or just set it in your shell via e.g.
export R_LIBS_USER="/some/other/path:${R_LIBS_USER}"
R CMD check asm_0.0.1.tar.gz
This mechanism is independent of how you call R CMD check it will work with or with devtools.
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.
Any reason why my package would say this? I have written C++ files that are included with the package, if that provides context. There is no other error info that comes along with this message.
A hunch: You are on Windows (or another OS which by default runs multi-arch like OS X), you are trying to run R CMD check and it fails to check on one of its two sub-architectures for lack of a package you depend upon.
Also note that R CMD check --no-multiarch ... is likely to help you here.