Hiding .Rproj.user when building packages developed in RStudio - r

A package's .Rbuildignore looks like this:
^.*[.]Rproj.*$
^\.Rproj\.user$
^.Rhistory$
[~]
Yet R CMD check mypackage --as-cran returns:
* checking for hidden files and directories ... NOTE
Found the following hidden files and directories:
.Rproj.user
From reading around, it looks like this is a "feature not a bug". But how do I just prevent .Rproj.user from appearing in the package file in the first place? Or do I have a problem with my regex?

.Rbuildignore is used to ignore files when building the package. If you build the package, the files that were ignored will not be in it. I think you are probably trying to check the source instead of checking the build. Try this
R CMD build mypackage
R CMD check mypackage_1.0.tar.gz --as-cran
Writing R Extensions says:
It is strongly recommended that the final checks are run on a tar archive prepared by R CMD build.

Related

R CMD build versus devtools::build() (Non-standard file/directory found at top level)

I am writing an R package and build and test it with:
Rscript -e "devtools::document()" && R CMD build . && Rscript -e "devtools::test();devtools::check()"
I get a note:
checking top-level files
Non-standard file/directory found at top level:
‘PosteriorBootstrap_0.0.1.tar.gz’
I get the note whether devtools::check() comes first or second.
This
thread suggests:
The note is telling you that you usually shouldn't have a file called
build in the top level of your package.
The tar.gz file is created by R CMD build and I get the same error even if I delete it before running it.
This
thread
suggests adding the tar.gz file to .Rbuildinore, which removes the note.
Another way to remove it is to run everything from devtools:
Rscript -e "devtools::document(); devtools::build(); devtools::load_all('.'); devtools::test(); devtools::check()"
And then I don't get that note.
What's the difference between R CMD build and devtools::build() and why does the former throw that note?
You are combining a number of steps that perform similar and/or competing functions. I would suggest reading this for a best-practice build and check workflow.
When you run R CMD build it builds the package to the current directory, which is the top level package directory. Therefore, when you run your checks, it sees the .tar.gz file in the package root, which is a non-standard file to have in a package, thus the warning. devtools::build() is smart and builds the package to the package parent directory (regardless of where you are calling it from). Trying to call R CMD commands mixed with devtools functions can create issues, because devtools also calls R CMD commands, so you may be duplicating actions at various points in time or causing commands to be called in the incorrect order.
Per the link above, a best-practice workflow would be:
Rscript -e "devtools::document();devtools::check();devtools::build()"
called from the package root, and you avoid dealing with R CMD altogether. If you want to use R CMD it would look something like this:
Rscript -e "devtools::document()" && cd .. && R CMD build PosteriorBootstrap && R CMD check PosteriorBootstrap*.tar.gz
starting in the package root and then changing to the parent directory.

I want to install package xlsx on R 2.8.1 on windows but I have to use .tar.gz old package when I need .zip

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.

R CMD check error : how to get rid of hidden files and directory in devel R package on windows?

I am building my R package on Rstudio, and I am running R CMD check for my packages. However, R CMD check warn few issues that possibly result in error. I checked my project home directory, indeed some files was hidden, now I set them up visible. Just out of curiosity, how to stop exist .gitignore, .Rproj.user, .git in my package directory ? R CMD check complain about these, because these files are not properties of packages, and also not being R package structure convention. How can I get rid of these warning in my Packages ? I tried to create dummy packages on my machine, but these properties always show up in package home directory, why this is happen when building R package with Rstudio ? How can I fix this CMD check error ? Any idea please ?
According to writing R Extension manual, R package structure supposed to be :
myPackage
`- inst
`- extdata
`- data1.csv
`- data2.csv
`- R
`- ...
`- NAMESPACE
`- man
`-hello.Rd
`- DESCRIPTION
Note :
This is session of R CMD check, part of error message as follow :
Found the following executable files:
.git/objects/00/bc868b99806415c87749e4a2e060f99eb811da
.git/objects/01/10cc76aa5573ca9401e72b36ad3672b39f23cb
.git/objects/01/5c9910f52a0560426a1b00e1e31e1f060afdfb
.git/objects/03/0ca1ef161838ebeb6a225f354a6a8eec95e472
....
...
.git/objects/fd/6439dfc6532e7e3a76e76b3e4ca4fd683b2c5e
.git/objects/fd/ebc184b447002ee6239231093eb026b9bb3aec
.git/objects/fe/02f64dd278d70ff2e5fb212834d131bc23fddb
.git/objects/ff/15763b397945d0ee2e2523eab1bfd460f84529
.git/objects/ff/5413a4dc5f2710fe30ad14f4eb10992ad5aee4
.git/objects/ff/b8e86c018008d3cee09871f76df3a7277cb1c7
Source packages should not contain undeclared executable files.
See section 'Package structure' in the 'Writing R Extensions' manual.
* checking for hidden files and directories ... NOTE
Found the following hidden files and directories:
.gitignore
.Rproj.user
.git
These were most likely included in error. See section 'Package
structure' in the 'Writing R Extensions' manual.
inst/ must be created in my package home directory, but I don't have this property when I am building my packages. Why I missed this directory ? Can any one point me how to possibly solve this problem ? How can I fix this CMD check error ? Thanks in advance :)
You are (likely) doing it wrong. Do the following:
cd ..
R CMD build yourDirectory/
R CMD check yourPackage_0.1.0.tar.gz
as the creation of the source tarball will automatically exclude the internal directories you want skipped. Which is why checking against tarballs (rather than directories) is the recommended and documented approach.
Note that in RStudio the option in the Build tag is called 'Check' and does just that: create a tarball first (after possibly running roxygen or other steps as configured) and then checks the tarball for you. That is as easy as clicking one button, or typing Ctrl-Shift-E (on my platform).
Finer control of additional files to exclude can be obtained via the .Rbuildignore file which tells R which other files to skip. A number of files and directories are already implicitly declared that way, including the git directories.

R package checking

I just recently submitted an update of my package to CRAN, and I was notified that a line in an .Rd file was too wide. Using the latest Rpatched version, I ran the R CMD check, everything checked out ok. I ran the --as-cran on the tarball and everything is ok. When I examined the .PDF file created after R CMD build, I do see that the line in the .PDF help file extended beyond page margin.
My question is where and how do I check for errors in the creation of the .PDF file? I've checked through Writing R Extensions, etc. and I can't find a specific statement.
Build and check your package R CMD build mypkg && R CMD check mypkg_1.2.3.tar.gz. Then look in mypkg.Rcheck/Rdlatex.log for warnings (like Overful \hbox) while processing the Rd file to latex.

R CMD install : clean libs before a new installation

If there is any option I can set to R CMD INSTALL to remove all installed libs ( under package installation directory) before a new installation?
I tried
R CMD install -c --preclean
But it does not work. Should I create a clean config?
PS : I am under windows.
EDIT more context:
I am developing a package. I generate the lib automatically at each build. So I need to remove the old ones each time I have a modification. Removing the entire library is Ok for me also.
I know this is old, but I just ran into this myself. I am assuming here by "installed libs" you mean libraries internal to your package on which your package depends. (In my case, it is libzip and libzippp that I am cleaning up.)
My solution was here: https://cran.r-project.org/doc/manuals/r-devel/R-exts.html#Configure-and-cleanup
Under a Unix-alike only, an executable (Bourne shell) script cleanup is executed as the last thing by R CMD INSTALL if option --clean was given, and by R CMD build when preparing the package for building from its source.
I created a file named "cleanup" that is a Bash script and change directories, call make distclean and remove so and o files there. This is called at the beginning and the end of the build/install process. The cleanup script is called from within the package directory.

Resources