I've read many posts here on how to install R packages from local files, from source etc. and still I have troubles installing (my own) package. The package was created using RStudio, Roxygen2 and RTools (Windows).
The package I'm trying to install (I do this in order to give an instruction so other people know how to install the package - I myself just compile and install the package from RStudio) can be downloaded here:
sjPlot-package
I also created a PACKAGE description, that is located on my server in the same directory as the package, using write_PACKAGES().
Now, if I try install.packages("sjPlot_0.1", contrib.url="http://www.strengejacke.de/R-Stuff/sjPlot/") I get following error message:
Warning in install.packages :
package ‘sjPlot_0.1’ is not available (for R version 3.0.2)
If I use install.packages("sjPlot_0.1", repos="http://www.strengejacke.de/R-Stuff/sjPlot/") I get following error message:
source repository is unavailable to check versions
Error in install.packages : Line starting ' ...' is malformed!
Also, a local install via install.packages("sjPlot_0.1", contriburl="C:/Users/Luedeke/Dropbox/R-Statistics/packages/") fails (this directory contains source-package, binary-package and PACKAGE descr. files).
I know there are a lot of postings on how to install R packages, and I read some of them - perhaps I missed the right one, if so, please excuse me for asking this question again.
My question is: How can I (or other people) install my R package (including installation of dependencies would be nice)?
Thanks in advance
Daniel
Your package does not pass R CMD check:
> R CMD check sjPlot_0.1.tar.gz
* using log directory ‘/home/edisz/Downloads/sj_tmp/sjPlot.Rcheck’
* using R version 3.0.2 (2013-09-25)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* checking for file ‘sjPlot/DESCRIPTION’ ... OK
* checking extension type ... Package
* this is package ‘sjPlot’ version ‘0.1’
* checking package namespace information ... OK
* checking package dependencies ... ERROR
Namespace dependencies not required:
‘HH’ ‘MASS’ ‘car’ ‘faraway’ ‘foreign’ ‘ggplot2’ ‘lmtest’ ‘plyr’
‘reshape2’ ‘scales’ ‘vcd’
See the information on DESCRIPTION files in the chapter ‘Creating R
packages’ of the ‘Writing R Extensions’ manual.
Exited with status 1.
Looking at your DESCRIPTION file, you'll see that the Collate and Import fields are missing.
Roxygen take care of the Collate fields (If you're using RStudio Configure roxygen to do so), however you have to write the Import field manually to the DESCRIPTION.
Looking at one of your functions:
#' #title Import SPSS dataset as data frame into R
[snip]
#'
#' #param path the file path to the SPSS dataset
#' #param enc the file encoding of the SPSS dataset
#' #return a data frame containing the SPSS data. retrieve value labels with \code{\link{sji.getValueLabels}}
#' and variable labels with \code{\link{sji.getVariableLabels}}
[snip]
#' #export
sji.SPSS <- function(path, enc=NA) {
# init foreign package
require("foreign")
# import data as data frame
data.spss <- read.spss(path, to.data.frame=TRUE, use.value.labels=FALSE, reencode=enc)
# return data frame
return(data.spss)
}
You see that there is a require('foreign') call, but no #import foreign tag.
I would suggest to remove the line require('foreign') (it's not needed, if you import the package) and add a #import foreign tag.
Than add to your Description file
Imports:
foreign
Do this with all other functions and packages.
Hope this helps (and is correct),
Related
I want to use arulessequences for sequence mining. I have to use it in Oracle R distribution version R 3.3.0 (last released) and The problem is that the last version of the arulesSequences package is R >= 3.3.2. So I get an error for this problem:
Error: this is R 3.3.0, package arulesSequences needs >=3.3.2
So I decided to compile the source code for older release. I downloaded an older package that needs R 3.2.5 or above. And I know that this package is depended to arules. so I have installed it already. I used following instructions to compile the arulessequences package:
in the source directory I run this command:
R CMD build arulesSequences
the output of this command is:
c:\rr\arulesSequences_0.2-17>R CMD build arulesSequences
* checking for file 'arulesSequences/DESCRIPTION' ... OK
* preparing 'arulesSequences':
* checking DESCRIPTION meta-information ... OK
* cleaning src Warning in cleanup_pkg(pkgdir, Log) : unable to run 'make clean' in 'src'
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* looking to see if a 'data/datalist' file should be added
* building 'arulesSequences_0.2-17.tar.gz'
a file named 'arulesSequences_0.2-17.tar.gz' get created but when I check it as below I get the following as output:
c:\rr\arulesSequences_0.2-17\arulesSequences>R CMD check arulesSequences
* using log directory 'c:/rr/arulesSequences_0.2-17/arulesSequences/arulesSequences.Rcheck'
using R version 3.4.0 (2017-04-21)
using platform: x86_64-w64-mingw32 (64-bit)
using session charset: ISO8859-1
checking for file 'arulesSequences/DESCRIPTION' ... OK
this is package 'arulesSequences' version '0.2-17'
checking package namespace information ... OK
checking package dependencies ... ERROR Package required but not available: 'arules'
See section 'The DESCRIPTION file' in the 'Writing R Extensions'
manual.
* DONE Status: 1 ERROR
I know the arules package is installed and I checked it. It seems the build process is not successful. do you have any idea to help solve this out?
You have to first install c/c++ compiler for R(called gcc) that is under R's additional build tools.
to do that, in RStudio goto File->New File ->c++ File.
It will show the following dialogue:
Then click on yes.
to compile a package under windows, you have to set repo to Null and type to source.
you can use this command to do that:
install.packages("SOURCEADDRESS",type="source",repo=null)
as #EugèneAdell mentioned above you have to first install arules. then arulessequences.
Instead of building, take the archive packages that seem to be ok for your R version and install them. On my Linux, this gives :
wget http://cran.univ-paris1.fr/src/contrib/Archive/arules/arules_1.5-0.tar.gz
R CMD INSTALL $HOME/arules_1.5-0.tar.gz
* installing to library ‘/home/ruser/R-3.2.5/lib64/R/library’
* installing *source* package ‘arules’ ...
...
** testing if installed package can be loaded
* DONE (arules)
wget http://cran.univ-paris1.fr/src/contrib/Archive/arulesSequences/arulesSequences_0.2-17.tar.gz
R CMD INSTALL $HOME/arulesSequences_0.2-17.tar.gz
* installing to library ‘/home/ruser/R-3.2.5/lib64/R/library’
* installing *source* package ‘arulesSequences’ ...
...
** testing if installed package can be loaded
* DONE (arulesSequences)
R
> library(arulesSequences)
Loading required package: arules
Loading required package: Matrix
Attaching package: ‘arules’
Maybe a more recent version for arules is possible, I just took the first one from the 1.5 series.
I tryed to install from file an old version of RgoogleMaps package with this command
install.packages("F://RgoogleMaps_1.1.9.15.tar.gz", repos = NULL, type="source")
but i found this error message:
* installing *source* package 'RgoogleMaps' ...
** package 'RgoogleMaps' successfully unpacked and MD5 sums checked
ERROR: a 'NAMESPACE' file is required
* removing 'C:/Users/Famiglia Mazza/Documents/R/win-library/3.1/RgoogleMaps'
* restoring previous 'C:/Users/Famiglia Mazza/Documents/R/win-library/3.1/RgoogleMaps'
Warning in install.packages :
running command '"C:/PROGRA~1/R/R-31~1.2/bin/x64/R" CMD INSTALL -l "C:\Users\Famiglia Mazza\Documents\R\win-library\3.1" "F://RgoogleMaps_1.1.9.15.tar.gz"' had status 1
Warning in install.packages :
installation of package ‘F://RgoogleMaps_1.1.9.15.tar.gz’ had non-zero exit status
what can I do? I'm using R on Windows
In R 2.14.0 a requirement was made that all packages had namespaces, but as a transitional arrangement those that didn't would have one automatically generated at install time.
A package R code but without a ‘NAMESPACE’ file will have a default
one created at R CMD build or R CMD INSTALL time, so all packages will
be installed with namespaces. A consequence of this is that
.First.lib() functions need to be copied to .onLoad() (usually) or
.onAttach(). For the time being, if there is an auto-generated
‘NAMESPACE’ file and no .onLoad() nor .onAttach() function is found
but .First.lib() is, it will be run as the attach hook (unless the
package is one of a list of known exceptions, when it will be run as
the load hook).
However, by R 3.0.0 this transitional arrangement was ended:
The transitional support for installing packages without namespaces
(required since R 2.14.0) has been removed. R CMD build will still add
a namespace, but a .First.lib() function will need to be converted.
R CMD INSTALL no longer adds a namespace (so installation will fail),
and a .First.lib() function in a package will be ignored (with an
installation warning for now).
As an exception, packages without a ‘R’ directory and no ‘NAMESPACE’
file can still be installed.
Therefore, I suggest you use an older version of R to run this package. One prior to R 3.0.0 should suffice, and the latest one prior to that is R 2.15.3.
I am writing a new extension for R. I have loaded all my functions into the Global Environment and ran
package.skeleton('package_name')
in the NAMESPACE file I have added all the required packages:
import(PerformanceAnalytics)
import(fBasics)
import(splines)
import(quantmod)
and added a LazyData:yes option to the DESCRIPTION file.
When I R CMD INSTALL package_name it goes without errors, only with several warnings:
When I run the package check I get
* using log directory 'folder path here'
* using R version 2.15.0 (2012-03-30)
* using platform: i386-pc-mingw32 (32-bit)
* using session charset: ISO8859-1
* checking for file 'package_name/DESCRIPTION' ... OK
* checking extension type ... Package
* this is package 'package_name' version '1.0'
* checking package namespace information ... OK
* checking package dependencies ... ERROR
Namespace dependencies not required:
'PerformanceAnalytics' 'fBasics' 'quantmod'
See the information on DESCRIPTION files in the chapter 'Creating R
packages' of the 'Writing R Extensions' manual.
In the R session typing library(package_name) all is being loaded without errors (few warnings with the naming conventions) but I cannot see any of the functions. What could possible cause that? When I do all the above with the tutorial example everything works fine. No S3 or S4 is being used - just plain R functions
Thanks,
Vladimir
I'm using setRefClass to create classes and since is part of the methods package, I presumed you need to declare this dependency as an import.
However, the following minimal example fails Rcmd.exe check when importing methods:
#' #docType package
#' #import methods
A <- setRefClass("A")
with the following error (my package is called Test):
==> Rcmd.exe check Test_1.0.tar.gz
<Lots of checks here...>
* checking package dependencies ... ERROR
Namespace dependency not required: 'methods'
See the information on DESCRIPTION files in the chapter 'Creating R
packages' of the 'Writing R Extensions' manual.
Exited with status 1.
So from what I can make out, it appears I'm being told to remove the import for methods and so keep hidden the package's dependency on methods. Is my interpretation correct and if so, why hide the dependency on methods?
My setup:
Roxygen2 3.0.0
R: 3.0.2 (Frisbee Sailing)
IDE: RStudio 0.98.490
OS: Windows 8.1
After more hunting around, I realised that in my haste I forgot to add Imports: methods to my DESCRIPTION file.
I am trying to create a package. It depends on several packages. I added the imports to the namespace file and the Depends in the description file.
I found possible solutions here and here, but these didn't work- I think because I am on CentOS.
This is what I see on my screen:
[hadoop#localhost RProjects]$ sudo R CMD check TextPreProcess
* using log directory ‘/home/hadoop/RProjects/TextPreProcess.Rcheck’
* using R version 2.15.1 (2012-06-22)
* using platform: x86_64-redhat-linux-gnu (64-bit)
* using session charset: UTF-8
* checking for file ‘TextPreProcess/DESCRIPTION’ ... OK
* checking extension type ... Package
* this is package ‘TextPreProcess’ version ‘1.0’
* checking package namespace information ... OK
* checking package dependencies ... ERROR
Packages required but not available:
‘RWeka’ ‘Snowball’ ‘lsa’ ‘plyr’ ‘snowfall’ ‘tau’ ‘tm’
See the information on DESCRIPTION files in the chapter ‘Creating R
packages’ of the ‘Writing R Extensions’ manual.
I went through Writing R Extentions but I couldn't derive a lot of insight as to how to solve my problem.
It's working now.
What I did was:
add ~/R/x86_64-redhat-linux-gnu-library/2.15 to .libPaths (That's where my R library was)
Detach all libraries in R
Restart the R session. (For multiple sessions, close all of them.)
install the required packages.
Check if the Imports & Exports are correct in the namespace file.
Check if the required fields are available in the Description file. Make sure all dependencies are handled between 'Depends', 'Imports', 'Suggests' and 'Enhances'.
Checked it. R CMD check <pkg>. Built it. R CMD build <pkg>. Installed it. R CMD INSTALL <tarball>.
Done.
I had the same problem because packages were installed but for different R versions.
To solve, I opened the old R version (the one the package was built under), and installed the missing packages under that version and it solved the problem.
E.g.
# Version should match the version your package was built in
R.version
# 3.5.1
install.packages(c('stringr', 'lubridate', 'testthat'))
Tips
If you need to check your R version, simply type R.version
If you need to switch R version, hold control while starting RStudio on windows, or on mac download a very simple application called RSwitch to instantly switch between version (you'll still need to restart the R session with .rs.restartR()