roxygen2 not creating .Rd documentation - r

I am unable to generate .Rd documentation files for my package using RStudio and Roxygen2. First, let me mention that I have gone through similar problems posted here and have already done the following:
Roxygen2 blocks initiated at the beginning of file with a #'
Configured Build Tools>Checked generate documentation with Roxygen> Configure > Checked all fields under 'Use roxygen to generate' and 'Automatically roxygenize when running'
Made sure there were no .Rd files in the 'man' folder
And even after that, when I perform a 'Build and Reload' on RStudio I get the following output (please note the line that reads: No man pages found in package MYPACKAGE:
=
=> devtools::document(roclets=c('rd', 'collate', 'namespace', 'vignette'))
>
Updating MYPACKAGE documentation
Loading MYPACKAGE
Documentation completed
==> Rcmd.exe INSTALL --no-multiarch --with-keep.source MYPACKAGE
installing to library C:/Users/user/Documents/R/win-library/3.3
installing source package 'MYPACKAGE' ...
** R
** data
* moving datasets to lazyload DB
** preparing package for lazy loading
No man pages found in package 'MYPACKAGE'
** help
* installing help indices
** building package indices
** testing if installed package can be loaded
DONE (MYPACKAGE)
Edit:
Upon further investigation, it appears that this was caused by the fact that I have sub-directories within my R directory, which is not supported by default. A possible solution was located here which, however, I haven't yet tried out. I will report back with the outcome as soon as I am able to perform the tests.

I had the same error. roxygen2 was creating correctly the md files in the /man directory but they were not found at compilation time. I had the following error.
No man pages found in package
After a bit of time I found that in one of the R file I had a source statement
source("C:/Users/vaulot/Google Drive/Scripts/R library/dv_function_pr2.R")
My guess is that there was some code in the source file interfering with roxygen2.

Related

After building a package, where is its zip file?

I have developed a very simple basic package called : mypackage in windows environment which contains one function
na2zero()
in R-Studio IDE i just did Build --> Clean and Rebuild resulted into below logs
==> Rcmd.exe INSTALL --preclean --no-multiarch --with-keep.source package
* installing to library 'C:/Users/NAME/Documents/R/R-4.0.0/library'
* installing *source* package 'mypackage' ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
converting help for package 'mypackage'
finding HTML links ... hello html
na2zero html
done
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (mypackage)
i'm able to invoke the functions which resides in mypackage, but my question is, i want to see the location of the package, i believe the extension will be .zip
so in which folder the package (mypackage) exists.?
In RStudio, the "Install and Restart" menu item in the Build pane will install the package directly into R, without creating an archive file.
If you want to create an archive, there are two kinds of those. Use "Build Source Package" (in the "More..." menu) to create a .tar.gz file, which can be installed in any current version of R, and also some past and future ones, on any supported platform.
Use "Build Binary Package" to create a binary package. On Windows, that would be a .zip file. It is only good for Windows and a very small range of R versions (typically if you build in R version X.Y.Z, you'll be able to use it for different value of Z, but not different values of X or Y). You won't be able to use it on Linux or MacOS.
For a simple package, you should almost always use the "Source Package" format. Only when you have compiled code (C, C++, Fortran) is it a good idea to use the "Binary Package" format: your users may not have the compiler needed to install it themselves. But you'll need to match your users' R versions very carefully.
For both Source and Binary packages, RStudio will put the archive file in the same folder as your package source is in, e.g. if your package version 1.0.0 is in
path/to/mypackage, it will produce path/to/mypackage_1.0.0.zip.

Installing R package ERROR: installing binary package failed

Complete newbie here, so there is probably something glaringly bad here. I created a Project following Hadley Wickham's book on R packages, and now I am trying add it to github for remote install (repository for reference).
Running devtools::install_github("alutterb/abcmlr") generated the following output:
Downloading GitHub repo alutterb/abcmlr#master
√ checking for file 'C:\Users\amlut\AppData\Local\Temp\RtmpMpn5uJ\remotes7146c405dd7\alutterb-abcmlr-918bf05/DESCRIPTION' ...
- preparing 'abcmlr':
√ checking DESCRIPTION meta-information ...
- checking for LF line-endings in source and make files and shell scripts
- checking for empty or unneeded directories
- building 'abcmlr_0.1.0.tar.gz'
Installing package into ‘C:/Users/amlut/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
* installing *binary* package 'abcmlr' ...
cp: unknown option -- )
Try '/Rtools/bin/cp --help' for more information.
ERROR: installing binary package failed
* removing 'C:/Users/amlut/Documents/R/win-library/3.5/abcmlr'
In R CMD INSTALL
Error in i.p(...) :
(converted from warning) installation of package ‘C:/Users/amlut/AppData/Local/Temp/RtmpMpn5uJ/file71463953e7b/abcmlr_0.1.0.tar.gz’ had non-zero exit status
In my repository, I have a Linux executable that is to be used with wsl as well as an .exe file that is called in my R code. These may be the culprits, but I am not entirely sure. The error states that it failed to install the binary package, but install_github() takes a source package, so I am not sure what is going on. Any help is appreciated.
Thank you.
EDIT: This problem is solved. It was because of a line in my DESCRIPTION file that had to do with Built.
Check your %PATH% and type: where cp.
Another cp (like one from the Git for Windows distribution) might overshadow the RTools cp, which might explain the error message.
As commented by the OP hkj447, the error was trigger by a line in the DESCRIPTION file:
Built: R 3.5.3; ; 2019-06-14 21:17:43 UTC; windows
As seen in this thread:
You have a field called 'Built:' in your package's DESCRIPTION file;
R normally tries to inject that field itself when it builds your package from sources.
I deleted "Built"'s line in DESCRIPTION and then installed again.
This time, no error appeared.

R packrat snapshot: upgrading package gives "stale" errors

I'm using packrat to freeze all versions of dependencies for an application. Sometimes I run into troubles with "staleness".
For instance, today I upgraded one package to a newer version. I did this by launching R in the packrat-managed project:
% R --quiet
Packrat mode on. Using library in directory:
- "~/git/myapp/app/packrat/lib"
> install.packages('MyPackage')
Installing package into ‘/Users/kwilliams/git/myapp/app/packrat/lib/x86_64-apple-darwin17.7.0/3.5.3’
(as ‘lib’ is unspecified)
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3537k 100 3537k 0 0 5530k 0 --:--:-- --:--:-- --:--:-- 5527k
* installing *source* package ‘MyPackage’ ...
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (MyPackage)
The downloaded source packages are in
‘/private/var/folders/zp/hj5hqfw970z0_78mrb_802lm0001z9/T/RtmpzfYDUz/downloaded_packages’
However, when I try to generate a new snapshot file, nothing happens:
> packrat::snapshot()
Snapshot written to '/Users/kwilliams/git/myapp/app/packrat/packrat.lock'
(The file is no different than before - the old version of MyPackage is still listed.)
I verified that the new version was indeed installed, and try the snapshot again:
> packageVersion('MyPackage')
[1] ‘7.4’
> packrat::snapshot()
The following packages are stale:
_
MyPackage 7.4
These packages must be updated by calling packrat::restore() before
snapshotting. If you are sure you want the installed versions of these
packages to be snapshotted, call packrat::snapshot() again with
ignore.stale=TRUE.
--
Snapshot operation was cancelled, no changes were made.
Huh? Not sure why the different results between the two times.
status() does seem to know the situation correctly:
> packrat::status()
The following packages are out of sync between packrat and your current library:
packrat library
MyPackage 7.3.1-22287 7.4
Use packrat::snapshot() to set packrat to use the current library, or use
packrat::restore() to reset the library to the last snapshot.
I figure I'll force it, so I add ignore.stale=TRUE:
> packrat::snapshot(ignore.stale=TRUE)
Upgrading these packages already present in packrat:
from to
MyPackage 7.3.1-22287 7.4
Fetching sources for MyPackage (7.4) ... FAILED
Error in snapshotSources(project, activeRepos(project), allRecordsFlat) :
Errors occurred when fetching source files:
Error in getSourceForPkgRecord(pkgRecord, sourceDir, availablePkgs, repos) :
Could not find sources for MyPackage (7.4).
Bummer. Might this have something to do with the fact that this is a locally-created package, installed from a local CRAN-alike? This would be a packrat bug, because (as noted above) install.packages() can find the source package just fine.
So I think there are two potential packrat bugs here:
Inability to snapshot the newly installed package
Inability to download source for the package
FWIW, I think the first problem is identical to the situation here: https://groups.google.com/forum/#!topic/packrat-discuss/HvD45u6w4Zg, in which Kevin Ushey (author/maintainer of packrat) says "it's possible that the logic around 'stale' packages can just go away."
Here are the workarounds I'm using to get back on my way:
As mentioned above, use ignore.stale=TRUE to force the snapshot even when it thinks things are stale.
Copy the source package manually to packrat/src/MyPackage/.
Now it succeeds:
> packrat::snapshot(ignore.stale=TRUE)
Upgrading these packages already present in packrat:
from to
MyPackage 7.3.1-22287 7.4
Snapshot written to '/Users/kwilliams/git/myapp/app/packrat/packrat.lock'
The packrat/packrat.lock file has been updated correctly:
% git diff
diff --git a/app/packrat/packrat.lock b/app/packrat/packrat.lock
index 6c17020..f717d29 100644
--- a/app/packrat/packrat.lock
+++ b/app/packrat/packrat.lock
## -30,9 +30,9 ## Hash: 9772da3bc51603a19a2b75f008fd63e3
Package: MyPackage
Source: source
-Version: 7.3.1-22287
+Version: 7.4
SourcePath: lib/MyPackage
-Hash: 4fe20417f5711b3c7c90a4efe3bb4bc7
+Hash: 880a308537e8de571106893e839386f6
...

Dynamic library not loading in R binary package build

I am trying to build a package with compiled C code in R using 'RStudio' and 'devtools' in a Windows environment.
Only one of the function uses the C code in src folder. The source package works fine. I can use all the functions. I am able to compile the C code using devtools::document() and the corresponding .dll and .o file also appears in the src folder. Then I can load the code using dev_tools::load_all or Ctrl+Shift+L and run all the functions.
However when I am building and reloading the package using Ctrl+Shift+B, I am not able to use the particular function. The function is missing from the package even thought the documentation is retained. I also get the error telling that the corresponding .dll is not loaded.
Error in library.dynam.unload(name, system.file(package = name)) :
DLL ‘mypackage.dll’ was not loaded
I get the same results when I am using devtools::build with binary=TRUE.
However I can find the .dll file in the library Documents\R\win-library\3.0\mypackage\libs\i386\mypackage.dll. Why is this dynamic library from compiled code not being loaded?
PS: 1) devtools::has_devel() is giving TRUE
2) I am forced to use .C instead of .Call.
This is the result of the R CMD INSTALL
* installing to library 'C:/Users/lenovo/Documents/R/win-library/3.0'
* installing *source* package 'mypackage' ...
** libs
make: Nothing to be done for `all'.
installing to C:/Users/lenovo/Documents/R/win-library/3.0/mypackage/libs/i386
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (mypackage)
I was able to solve this on Windows 10 with R 3.5 by adding the following function to a file in the R/ folder.
.onUnload <- function (libpath) { library.dynam.unload("mypackage", libpath)}
Here is the reference where I found it.

Building R package: "No man pages found in package"

My previously-functioning R package lllcrc recently broke, so I tweaked it, and now I'm having trouble building it again because it acts like it can't see my documentation files:
R CMD INSTALL lllcrc
* installing to library ‘/home/[...]/3.1’
* installing *source* package ‘lllcrc’ ...
** R
** preparing package for lazy loading
** help
No man pages found in package ‘lllcrc’
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (lllcrc)
This is totally weird because I definitely have a complete set of .Rd files in the man folder; in fact, I generated all of these using roxygen2, and all of this worked previously. The R CMD INSTALL even works enough so that the package actually installs and all of its examples run. But documentation is missing. Running ?foo just gives a "no documentation" message.
Another thing: R CMD Rd2pdf lllcrc generates the .pdf documentation as I would expect.
Any ideas?
I just had the same error message ... if you are using roxygen and RStudio then your problem might be the same. The reason became apparent when looking at "Configure build tools" in the "Build" drop-down menu: you need to tick the checkbox "Generate documentation with Roxygen". After that, everything worked.

Resources