Package documentation - RStudio, roxygen, devtools - r

I am confused. I was used to the following flow when creating packages:
create new package in RStudio using gui (named e.g. testPackage
modify some files (let's say DESCRIPTION for beginning)
write:
-
library(devtools)
document()
check()
load_all()
But now, for some reason document() does not propagate changes in DESCRIPTION to testPackage-package.Rd in man folder anymore. I get the following when using document():
> document()
Updating testPackage documentation
Loading testPackage
First time using roxygen2 4.0. Upgrading automatically...
When I run check() I see in one of the lines:
Warning:
...r/packages/testPackage.Rcheck/00_pkg_src/testPackage/man/testPackage-package.Rd:32: All text must be in a section
Unfortunately, there is no additional information in 00install.out as indiciated by check(). I am on Windows, R 3.1.2, RStudio 0.98.1091, devtools 1.7.0, roxygen2 4.1.0.
Did the process change or I have some inconsistent set of packages installed?

Related

How do i keep source files when using R's devtools library function 'install'

I am trying to build an R package (DESeq2) from source so that I can debug it. I've installed all the dependencies required and I'm following Hillary Parker's instructions for creating R packages. I'm running this on CentOS 6.6 using R-3.4.2.
I run :
library("devtools")
install("DESeq2", keep_source=TRUE)
It installs it in the directory with all my other R libraries. When I look at the installed DESeq2 library it is missing all the DESeq2/R/*.R and DESeq2/src/*.cpp files.
QUESTION : Where are these files and why didn't they get installed? This does not seem like the expected behavior.
R uses binary database format for installed packages to pack the objects into a database-alike file format for efficiency reasons (lazy loading). These database files (*.rdb and *.rdx) are stored in the R sub folder of the package installation path (see ?lazyLoad).
Even if
you are looking at the right place to find the installed package (use .libPaths() in R to find the installation folder)
and you have installed the package with the source code (like you did or
via install.packages("a_CRAN_package", INSTALL_opts = "--with-keep.source"))
you will not find R files in R folder there.
You can verify that the source code is available by picking one function name from the package and print it on the console. If you can see the source code (with comments) the package sources (R files) are available:
print(DeSeq2::any_function)
To make the source code available for debugging and stack traces you can set the option keep.source.pkgs = TRUE (see ?options) in your .Rprofile file or via an environment variable:
keep.source.pkgs:
As for keep.source, used only when packages are
installed. Defaults to FALSE unless the environment variable
R_KEEP_PKG_SOURCE is set to yes.
Note: The source code is available then only for newly installed and updated packages (not for already installed packages!).
For more details see: https://yetanothermathprogrammingconsultant.blogspot.de/2016/02/r-lazy-load-db-files.html

R - Importing 'xlsx' package to my own package doesn't work

I am creating my own package. I am using a lot of existing packages in it and they work. I am using the same procedure for the xlsx package but it doesn't work. I have xlsx in Imports: in my DESCRIPTION file. I have #import xlsx in my respective .R file. I also tried #importFrom write.xlsx for a particular function with the same result. I am using libraries devtools and roxygen2 for creating the package. My new package is build, but if I proceed Check, an error occurs:
Installation failed.
See 'C:/Work/Package/MyPackage.Rcheck/00install.out' for details.
* DONE
Status: 1 ERROR
Warning: running command '"C:/R/R-3.3.3/bin/x64/Rcmd.exe" INSTALL -l "C:/Users/Work/Package/MyPackage.Rcheck" --no-html "C:\Users\Work\Package\MyPackage.Rcheck\00_pkg_src\MyPackage"' had status 1
and
checking whether package 'MyPackage' can be installed ... ERROR
Installation failed.
See 'C:/Users/Work/Package/MyPackage.Rcheck/00install.out' for details.
R CMD check results
But there is no .out file from the error. The whole file MyPackage.Rcheck occurs for a short time during the checking process, but then it disappears. So I am not able to check the .out file and find an error.
I also tried to use command library(xlsx) inside my code. In this situation the process of building and checking has less problems. There is only one warning and one note:
WARNING
'library' or 'require' call not declared from: 'xlsx'
'library' or 'require' call to 'xlsx' in package code.
Please use :: or requireNamespace() instead.
See section 'Suggested packages' in the 'Writing R Extensions' manual.
NOTE
MyFunction: no visible global function definition for 'write.xlsx'
But I know that if I would like to upload my code to the CRAN there should not be any warnings.
I also know that xlsx package has two dependencies: rJava and xlsxjars. If I put them to Imports: in DESCRIPTION file and also use the #import in my .R file the same problem appears. I also tried used Depends: with the same results.
Thank you all for your help.
By disabling RStudio option "Cleanup output after successful R CMD check" I found the .out file. The problem was in Java on my computer. I am using 64-bit version of R and I have also 64-bit version of Java. So the package xlsx normally worked. But I have also installed 32-bit version of R on my computer but there was no 32-bit version of Java. After installing it, everything works. Every version of R must have the same version of Java. An oppositely, there must not be Java version without R opposite.
I had the same issue over and over running in a Linux environment without the usage of Rstudio.
My issue was #importFrom xlsx read.xlsx, removing this and adding a call xlsx::read.xlsx('myFile.xlsx', 1) in the code where read.xlsx is used, then running R -e "devtools::document() works properly. After this, I've added again #importFrom xlsx read.xlsx and removed the xlsx:: and then is working just fine.
I think this could be something related to first setting up configurations from xlsx package since before doing this I never made a call from it.

Command line equivalent to "Run Document" for R versions >= 3.2.2 so that markdown files can access the global environment

I am making an interactive R Markdown report, with Shiny providing the interactivity. I am having a problem where I cannot access variables in the global environment when I click "Run Document" in RStudio (as described here). That same sections describes how you can use rmarkdown::run(...) to run the document from the command line, and this question shows that this allows the report to access variables in the global environment.
However, for my version of R I get the following error in the pop up window:
Error: pandoc version 1.12.3 or higher is required and was not found.
When I try and install pandoc, I get:
> install.packages("pandoc")
Warning in install.packages :
package ‘pandoc’ is not available (for R version 3.2.2)
Is there a fix for this?
pandoc isn't a R package. It's something you need installed on your system. RStudio provides it if you don't have it installed. Updating RStudio should fix the issue if you don't want to install pandoc manually.

In continuation to previously asked "Unable to work with R-extension in NetLogo"

After changing all the needed environment varaibles ( Control Panel/ System/Advanced system settings/Environment Variables) in windows 8, when I am installing rJava Package I get errors as below
I tried in MsDOS immediately after changing environment variables,
first step >R "it was successful"
second >install.packages("rJava") "got error in this step"
then I tried >install.packages("rJava", repos="https://cran.rstudio.com/") "but again I did not succeeded"
I am tired of trying all this, I referred many links already but all in vain. Yes, I am using Proxy also. Please help any one.
1) It seems a download problem first. So do this:
Download rJava_0.9-8.zip from CRAN (cran.r-project.org/web/packages/rJava/index.html). Then, in Revolution R Enterprise; Packages - "Install Packages From local Zip Files..." - Choose rJava_0.9-8.zip - OK. If the problem is solved then OK.
If the problem persists, try the following Step.
2) Look at DESCRIPTION file in rJava (in library location):
Package: rJava
Version: 0.9-8
....
Depends: R (>= 2.5.0), methods
....
NeedsCompilation: yes
Your R version may be incompatible. Look at the warning: "rJava is not available for R3.3.0" in your screenshot. So do this:
Unzip file rJava_0.9-8.zip to R's working directory; the folder rJava is created there. Change R version accordingly (you may introduce lower version number in Depends section). Save the changed DESCRIPTION file. Apply classical procedure:
library(roxygen2) # install this package first if not done yet
library(devtools) # install this package first if not done yet
library(digest) # install this package first if not done yet
Note: Since rJava folder is created manually, no package.skeleton is needed at this stage.
roxygenize("rJava")
build("rJava")
install("rJava")
The above technique must solve the problem (It solved previously many R version problems!).
Analyze this one also:
Install a specific release of bioconductor package (where the solution I wrote solved the problem of the questioner).
If you still have problems, trigger the following:
sessionInfo(); getwd(); .libPaths()
and print the output in your question so that we can analyze if you have any machine-spesific or installation-spesific problems.

problem when installing RTextTools for R

I was trying to install RTextTools package for R, but failed. Here is the output from the screen
> > install.packages("RTextTools")
Warning in install.packages("RTextTools") :
argument 'lib' is missing: using 'C:\Users\datamining\Documents/R/win-library/2.10'
--- Please select a CRAN mirror for use in this session ---
Warning: unable to access index for repository http://www.stats.ox.ac.uk/pub/RWin/bin/windows/contrib/2.10
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
package ‘RTextTools’ is not available
What's the reason for this problem, and how to fix it? Thanks.
There are two distinct, but related, issues:
You are running version 2.10 of R which is two years old. CRAN supports only the current version with pre-built binaries. You could try installing from source.
RTextTools, as can be seen on its CRAN page also requires at least R version 2.13.
So in short: you should upgrade.
I have resolved the issue. I have Download RTextTools From Given Link.

https://cran.r-project.org/src/contrib/Archive/RTextTools/
and copy RTextTools_1.4.2.tar.gz file in project root folder then run this command in project folder in terminal
"R CMD INSTALL RTextTools_1.4.2.tar.gz"
After running this command I receive below error
"ERROR: dependencies ‘SparseM’, ‘randomForest’, ‘tree’, ‘e1071’, ‘ipred’, ‘caTools’, ‘maxent’, ‘glmnet’, ‘tau’ are not available for package ‘RTextTools’".
Now install each dependencies from RStudio or RConsole (Any Editor used by you) by simply running this code.
install.packages("caTools").
Install all 9 required packages One By One (In My Case it was 9 Packages Dependencies required by RTextTools) all packages will be installed except 'maxent'.
Now download maxent from the given link.
https://cran.r-project.org/src/contrib/Archive/maxent/.
and copy maxent_1.3.3.1.tar file in project folder then run this command in project folder in terminal.
"R CMD INSTALL maxent_1.3.3.1.tar"
Now For RTextTools Run this command again in Terminal.
"R CMD INSTALL RTextTools_1.4.2.tar.gz"
All is done Now..
But the Last Step is
Load the RTextTools using.
library(RTextTools)
You will see one more Error: Load SparseM Now Loading SparseM use code below.
library(SparseM)
and in the last Load RTextTools
library(RTextTools)
RTextTools is dependent on a number of packages, most of which require R 2.13+. You should always keep R updated to the latest version, since each update contains numerous bug fixes and performance enhancements.
If you can't install packages from repository or the packages are not available anymore, just follow this steps:
Install.packages("devtools")
check -- library("devtools")
install_github("cran/maxent")
install_github("cran/RTextTools")

Resources