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.
Related
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.
I'm running R CMD INSTALL --build package on a windows computer. My package imports a couple of other packages which themselves depend on some more packages. I have all dependencies installed in the local r_libs folder and everything works.
Now sometimes I have the my package source code on a different windows computer. On this computer I don't have all the dependency packages installed.
When I try to use R CMD INSTALL --build package, I get the obvious "ERROR: dependencies 'package a', 'package b', etc, are not available for package".
My question is: Can I build the package using R CMD INSTALL --build without the dependency checks and without removing the Import and Depends entries in the DESCRIPTION file?
After consulting --help, I tried the --no-test-load option but no luck.
I reckon you want to build a .zip binary version of the package on a computer where not all dependencies are installed. And I'm afraid I'll have to disappoint you, as this won't be possible.
Building a binary package is done in two steps: first the package is installed from source (that's why you have to use R CMD INSTALL and then the created binaries are zipped in a convenient format for installation on a windows machine. The dependencies are checked at time of installation from source, and any missing dependencies will throw the error you're facing.
As R needs information from the dependencies at time of installation from source, you can't get around installing them before building the whole thing. This also makes sense. An installed package in R contains a set of .rds files which contain package information in a more convenient format for R. In order to create that information for the NAMESPACE file, it needs to be able to access the packages from which functions are imported. If not, it can't construct the correct information about the namespace.
So your only option is to install the dependencies on the computer you use to build. And if you actually want to use the package on that computer, you'll have to install those dependencies anyway.
More information:
R Internals : https://cran.r-project.org/doc/manuals/r-release/R-ints.html#Package-Structure
Writing R Extensions: https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Package-namespaces
I've built a Packrat project with several packages installed in the Packrat private library. I want to take the code and bring it, along with the Packrat library, to another system. The system I built the library in is Windows 7 running R 3.2.2 from Rstudio, and the system I'm moving it to is a Linux machine running R 3.1.2 from the command line. The version of packrat on the Windows machine is 0.4.6-1. Here is a rundown of the actions I took: on the Windows machine I ran
> packrat::bundle(include.lib=TRUE)
I took the resulting bundle and moved it over to the Linux system where I unzipped it using tar -zxvf packrat_bundle.tar.gz. I then entered the newly unzipped directory and started R. From there, packrat automatically bootstrapped (due to the line source("packrat/init.R") packrat placed in .Rprofile) and gave the following output
Packrat is not installed in the local library -- attempting to bootstrap an installation...
> Installing packrat into project private library:
- '/home/code/packrat/lib/x86_64-unknown-linux-gnu/3.1.2'
* installing *source* package âpackratâ ...
** package âpackratâ successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (packrat)
> Attaching packrat
> Restoring library
Already up to date.
> Packrat bootstrap successfully completed. Entering packrat mode...
Updating system packages ('3.2.2' -> '3.1.2')
Packrat mode on. Using library in directory:
- "/home/code/packrat/lib"
Warning message:
In restore(restart = FALSE) :
The most recent snapshot was generated using R version 3.2.2
After this, the output from .libPaths() is
> .libPaths()
[1] "/home/code/packrat/lib/x86_64-unknown-linux-gnu/3.1.2"
[2] "/home/code/packrat/lib-ext"
[3] "/home/code/packrat/lib-R"
The issue is that the library that I created on the Windows machine is contained in the directory /home/code/packrat/lib/x86_64-w64-mingw32/3.2.2. As such, I have to add that to .libPaths to get the packrat library to work correctly. I don't mind having to change .libPaths by hand, but I feel strongly like I might be doing something incorrectly that is causing the problem.
Thanks for any help!
It turns out that the issue I was having was that I hadn't snapshotted packrat before attempting to move it to the other system. I solved the problem by first running packrat::snapshot() and then proceeding mostly as before.
I was under the mistaken assumption that by using packrat::bundle(include.lib=TRUE) that I could transfer my library that way. That's not the case, especially when the library needs to be moved to another system and rebuilt from source. Snapshotting first took care of the source rebuild, and packrat correctly bootstrapped.
My answer does not concern the question but I want to write here so maybe someone will read this and save so much time and frustration.
It has been 2 yrs since this question was posted. I used packrat package a year ago and still today i find it simply not usable. I tried to install dplyr and it takes 1 hr to install BH package ( dependency).
Much better working with checkpoint package. You have to specify 1 function
checkpoint("your_snapshot_date")
and you are ready to share your code as a reproducible example. Time to install dplyr: 3 min.
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.
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.