I'm trying to install the package PerformanceAnalytics using the following code in a Jupyter Notebook, which I've used to install many packages successfully, such as ggplot2, with the following code:
install.packages("PerformanceAnalytics", repos='http://cran.r-project.org')
But I read on many other questions that adding dependencies=TRUE would solve the issue. Unfortunately, it did not. I keep getting the following error message.
install.packages("PerformanceAnalytics", repos='http://cran.r-project.org',
dependencies=TRUE)
Warning message in install.packages("PerformanceAnalytics", repos =
"http://cran.r-project.org"): “installation of package ‘PerformanceAnalytics’
had non-zero exit status”Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
The package installs without a problem in the R app and RStudio. Is there something I'm missing that Jupyter requires for this specific package? I'm using macOS 10.12.5. Below is the info when I run sessionInfo().
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin11.4.2 (64-bit)
Running under: macOS Sierra 10.12.5
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] R6_2.2.0 magrittr_1.5 IRdisplay_0.4.4 pbdZMQ_0.2-4
[5] tools_3.3.2 crayon_1.3.2 uuid_0.1-2 stringi_1.1.2
[9] IRkernel_0.7.1 jsonlite_1.1 stringr_1.1.0 digest_0.6.10
[13] repr_0.10 evaluate_0.10
The solution from the question at Is it possible to install bioconductor package 'rain' in R Jupyter notebook? solved my issue as well. I was using Anaconda's version of R. I uninstalled Anaconda and instead installed Jupyter Notebook and IRkernal manually which resolved my issue. See the answer from the above link for full details.
The following code works fine in the R console (R 3.3.0):
m = system.file("external/pores_1.mtx", package = "Matrix")
x = Matrix::readMM(m)
I can put it in a script and it runs fine in R console as:
source("test.R")
However, when I execute it as Rscript --vanilla test.R or Rscript test.R, I get an error:
Error in validObject(.Object) :
invalid class “dgTMatrix” object: Not a valid 'Mnumeric' class object
Calls: <Anonymous> -> new -> initialize -> initialize -> validObject
Execution halted
I don't know if this is related to that specific function. I am guessing this has something to do with how Rscript works, but I used it with various other libraries and functions previously and have never seen anything like this. Any idea what is happening?
I can confirm ... I'm getting the exact same error when running a script containing a call to glmnet(). I was able to trace it back to the Matrix package, on which glmnet depends.
I back-rev'd my R version from v3.3.3 -> v3.3.2 and the error disappeared. I then checked the sessionInfo() between the two and discovered that the version of the Matrix package differed ... it is 1.2-8 (in v3.3.3) and 1.2-7.1 (in v3.3.2). To confirm, I simply replaced the "OK" version of Matrix (7.1) with the "broken" version and the error returned.
I can also confirm that explicitly loading the methods package via library(methods) resolves the error (somehow?), which explains the differing behavior between the console call and the Rscript call from the command line.
So, it appears we have 2 work-arounds:
library(methods)
back rev your version of Matrix to 1.2-7.1.
Neither is super satisfactory ... I'd just like to know what's going on with Matrix 1.2-8. Maybe it'll be bug-fixed in the next version.
If you're interested, here is my sessionInfo():
R version 3.3.3 (2017-03-06)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.2 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets base
other attached packages:
[1] glmnet_2.0-5 foreach_1.4.3 Matrix_1.2-8
loaded via a namespace (and not attached):
[1] codetools_0.2-15 grid_3.3.3 iterators_1.0.8 methods_3.3.3
[5] lattice_0.20-35
Oh dear.
I'm pretty (not 100% !) sure that this problem should not apply in newer version of R and Matrix.
Still I would claim this is not a Matrix bug in a proper sense, rather either an 'Rscript' vs 'R' bug -- as #Stu Field mentions already; Rscript does not by default attach the methods package to the search() path, but regular R does.
OTOH, R CMD check Matrix nowadays should try to run Matrix without the methods package being in the search path, and hence the problem should not be present from Matrix 1.2-9 and newer, i.e., by default from R 3.4.0 and newer or then update the 'Matrix' package if you have an older version of R.
Again: Can you please confirm that the problem is gone with R 3.4.0 (which has Matrix 1.2-9 "along with it") ?
Here is a more useful example script, I called Rscript-tst.R.
Run as
Rscript --vanilla Rscript-tst.R > Rscript-tst.Rout 2>&1
or (as myself with many R versions installed) something like
`R-3.4.0 RHOME`/bin/Rscript --vanilla Rscript-tst.R > Rscript-tst.Rout_R340 2>&1
Rscript-tst.R :
options(echo = TRUE)# << even with "Rscript" or --slave ...
(m <- system.file("external/pores_1.mtx", package = "Matrix"))
packageDescription("Matrix")
## This *load*s the Matrix package but does not attach it to search()
str(Matrix::readMM)
sessionInfo()
x <- Matrix::readMM(m)
## used to fail because 'methods' was not "there" (in Rscript only)
I followed the official guide to install RStudio Server. Everything works fine, but the functions, fix and edit, are not available.
For instance, I have a data.frame called "data" as follows.
1,2,3
4,5,6
7,8,9
The command "View(data)" works fine. But when I execute the command "edit(data)" or "fix(data)", it comes some error messages.
The error messages of "fix(data)" :
Error in .External2(C_dataentry, datalist, modes) :
unable to start data editor
In addition: Warning message:
In edit.data.frame(get(subx, envir = parent), title = subx, ...) :
unable to open display
The error message of "edit(data)" :
Error in edit : Editing of data frames and matrixes is not supported in RStudio.
I ran the same codes on my local rstudio (windows 8.1), and all the functions work fine!
It's really wired... Anyone can help me? Thanks a lot!
p.s. I read this post already, but it doesn't work for me.
sessionInfo:
R version 3.1.3 (2015-03-09)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
locale:
[1] LC_CTYPE=zh_TW.UTF-8 LC_NUMERIC=C LC_TIME=zh_TW.UTF-8
[4] LC_COLLATE=zh_TW.UTF-8 LC_MONETARY=zh_TW.UTF-8 LC_MESSAGES=zh_TW.UTF-8
[7] LC_PAPER=zh_TW.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=zh_TW.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_3.1.3
I had the same problem, but then I installed the XQuartz package from here: https://www.xquartz.org/
And then another thread, from a while back, reminded me that I needed to restart my Mac for the x11 app to take effect: https://stackoverflow.com/a/36486555
I am trying to run a simple MR program using rmr2 in a single node Hadoop cluster. Here is the environment for the setup
Ubuntu 12.04 (32 bit)
R (Ubuntu comes with 2.14.1, so updated to 3.0.2)
Installed the latest rmr2 and rhdfs from here and the corresponding dependencies
Hadoop 1.2.1
Now I am trying to run a simple MR program as
Sys.setenv(HADOOP_HOME="/home/training/Installations/hadoop-1.2.1")
Sys.setenv(HADOOP_CMD="/home/training/Installations/hadoop-1.2.1/bin/hadoop")
library(rmr2)
library(rhdfs)
ints = to.dfs(1:100)
calc = mapreduce(input = ints, map = function(k, v) cbind(v, 2*v))
from.dfs(calc)
The mapreduce job fails with the below error message in hadoop-1.2.1/logs/userlogs/job_201310091055_0001/attempt_201310091055_0001_m_000000_0/stderr
Error in library(functional) : there is no package called ‘functional’
Execution halted
java.lang.RuntimeException: PipeMapRed.waitOutputThreads(): subprocess failed with code 1
at org.apache.hadoop.streaming.PipeMapRed.waitOutputThreads(PipeMapRed.java:362)
at org.apache.hadoop.streaming.PipeMapRed.mapRedFinished(PipeMapRed.java:576)
But, the sessionInfo() shows that functional package has been loaded
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: i686-pc-linux-gnu (32-bit)
>locale:
[1] LC_CTYPE=en_IN LC_NUMERIC=C LC_TIME=en_IN
[4] LC_COLLATE=en_IN LC_MONETARY=en_IN LC_MESSAGES=en_IN
[7] LC_PAPER=en_IN LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_IN LC_IDENTIFICATION=C
>attached base packages:
[1] stats graphics grDevices utils datasets methods base
>other attached packages:
[1] rhdfs_1.0.6 rJava_0.9-4 rmr2_2.3.0 reshape2_1.2.2 plyr_1.8
[6] stringr_0.6.2 **functional_0.4** digest_0.6.3 bitops_1.0-6 RJSONIO_1.0-3
[11] Rcpp_0.10.5
Update : I am able to run a R MR job reading and writing from STDIO without using the rmr2 and the rhdfs libraries as mentioned here. So, for now my guess is that the problem is isolated to rmr2 and the rhdfs packages.
How to get around this problem?
Install the dependencies for rmr2/rhdfs in a system directory instead of a custom directory (~/R/x86_64-pc-linux-gnu-library/3.0). This can be done running R as sudo and then installing the dependencies. Thanks to Antonio for the help in the RHadoop forums.
The most common solution of these kind of problem is re-installation since in sesssionInfo()
you are getting
**functional_0.4**
while when i did sessionInfo() i got
functional_0.4
i guess there is some missing dependencies you might be missing so use from your R console
install.packages("functional",dependencies="TRUE")
to fix any problem due to any other packages .
P.S: Choose cloud-0 mirror from the available ones.
If still that does not help i recommend you use r-base-dev as your R version though i don't have a reason to justify this using http://cran.r-project.org/bin/linux/ubuntu/README
sudo apt-get install r-base-dev
Thanks
I am in a process of figuring out how to use my university cluster. It has 2 versions of R installed. System wide R 2.11 (Debian 6.0) and R 2.14.2 in non-standard location.
I am trying to use MPI together with snow. The code I am trying to run is the following
library(snow)
library(Rmpi)
cl <- makeMPIcluster(mpi.universe.size()-1)
stopCluster(cl)
mpi.quit()
It works without the problems on R 2.11. (I launch the script with mpirun -H localhost,n1,n2,n3,n4 -n 1 R --slave -f code.R). Now when I try to do it with R 2.14.2, I get the following message:
Error: This is R 2.11.1, package 'snow' needs >= 2.12.1
In addition: Warning message:
So it seems that R loads the package snow version compiled for R 2.11. I've installed snow under R 2.14 into my home folder and I added the following lines to my code:
.libPaths("/soft/R/lib/R/library")
.libPaths("~/R/x86_64-pc-linux-gnu-library/2.11")
print(.libPaths())
print(sessionInfo())
print(version)
And the output before the error confirms that I am indeed running R 2.14.2 and my R packages folder is first in search path. But I still get the error.
So my question is how do I determine which version of package is loaded in R? I can see with installed.packages all the packages which are installed, so maybe there is some function which lists similar information for loaded packages?
You can use sessionInfo() to accomplish that.
> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] graphics grDevices utils datasets stats grid methods base
other attached packages:
[1] ggplot2_0.9.0 reshape2_1.2.1 plyr_1.7.1
loaded via a namespace (and not attached):
[1] colorspace_1.1-1 dichromat_1.2-4 digest_0.5.2 MASS_7.3-18 memoise_0.1 munsell_0.3
[7] proto_0.3-9.2 RColorBrewer_1.0-5 scales_0.2.0 stringr_0.6
>
However, as per comments and the answer below, there are better options
> packageVersion("snow")
[1] ‘0.3.9’
Or:
"Rmpi" %in% loadedNamespaces()
You can use utils::packageVersion to see what version of a package is installed:
> packageVersion("snow")
[1] ‘0.3.9’
Note that
A package will not be ‘found’ unless it has a DESCRIPTION file which contains a valid Version field. Different warnings are given when no package directory is found and when there is a suitable directory but no valid DESCRIPTION file.
Although it sounds like you want to see what version of R you are running, in which case #Justin's sessionInfo suggestion is the way to go.
Technically speaking, all of the answers at this time are wrong. packageVersion does not return the version of the loaded package. It goes to the disk, and fetches the package version from there.
This will not make a difference in most cases, but sometimes it does. As far as I can tell, the only way to get the version of a loaded package is the rather hackish:
asNamespace(pkg)$`.__NAMESPACE__.`$spec[["version"]]
where pkg is the package name.
EDIT: I am not sure when this function was added, but you can also use getNamespaceVersion, this is cleaner:
getNamespaceVersion(pkg)
To check the version of R execute : R --version
Or after you are in the R shell print the contents of version$version.string
EDIT
To check the version of installed packages do the following.
After loading the library, you can execute sessionInfo ()
But to know the list of all installed packages:
packinfo <- installed.packages(fields = c("Package", "Version"))
packinfo[,c("Package", "Version")]
OR to extract a specific library version, once you have extracted the information using the installed.package function as above just use the name of the package in the first dimension of the matrix.
packinfo["RANN",c("Package", "Version")]
packinfo["graphics",c("Package", "Version")]
The above will print the versions of the RANN library and the graphics library.
You can try something like this:
package_version(R.version)
getRversion()
GUI solution:
If you are using RStudio then you can check the package version in the Packages pane.
Use the R method packageDescription to get the installed package description and for version just use $Version as:
packageDescription("AppliedPredictiveModeling")$Version
[1] "1.1-6"
Based on the previous answers, here is a simple alternative way of printing the R-version, followed by the name and version of each package loaded in the namespace. It works in the Jupyter notebook, where I had troubles running sessionInfo() and R --version.
print(paste("R", getRversion()))
print("-------------")
for (package_name in sort(loadedNamespaces())) {
print(paste(package_name, packageVersion(package_name)))
}
Out:
[1] "R 3.2.2"
[1] "-------------"
[1] "AnnotationDbi 1.32.2"
[1] "Biobase 2.30.0"
[1] "BiocGenerics 0.16.1"
[1] "BiocParallel 1.4.3"
[1] "DBI 0.3.1"
[1] "DESeq2 1.10.0"
[1] "Formula 1.2.1"
[1] "GenomeInfoDb 1.6.1"
[1] "GenomicRanges 1.22.3"
[1] "Hmisc 3.17.0"
[1] "IRanges 2.4.6"
[1] "IRdisplay 0.3"
[1] "IRkernel 0.5"
Old question, but not among the answers is my favorite command to get a quick and short overview of all loaded packages:
(.packages())
To see which version is installed of all loaded packages, just use the above command to subset installed.packages().
installed.packages()[(.packages()),3]
By changing the column number (3 for package version) you can get any other information stored in installed.packages() in an easy-to-read matrix. Below is an example for version number and dependency:
installed.packages()[(.packages()),c(3,5)]
To add on #GSee's answer, note that the returned value of utils::packageVersion() is not a character and that you can perfectly use it to write conditions:
packageVersion("dplyr")
#> [1] '1.0.7'
packageVersion("dplyr")>1
#> [1] TRUE
packageVersion("dplyr")>'1.0'
#> [1] TRUE
packageVersion("dplyr")>'1.1'
#> [1] FALSE
Created on 2021-08-23 by the reprex package (v2.0.0)
Use the following code to obtain the version of R packages installed in the system:
installed.packages(fields = c ("Package", "Version"))
Search() can give a more simplified list of the attached packages in a session (i.e., without the detailed info given by sessionInfo())
search {base}- R Documentation
Description: Gives a list of attached packages. Search()
search()
#[1] ".GlobalEnv" "package:Rfacebook" "package:httpuv"
#"package:rjson"
#[5] "package:httr" "package:bindrcpp" "package:forcats" #
#"package:stringr"
#[9] "package:dplyr" "package:purrr" "package:readr"
#"package:tidyr"
#[13] "package:tibble" "package:ggplot2" "package:tidyverse"
#"tools:rstudio"
#[17] "package:stats" "package:graphics" "package:grDevices"
#"package:utils"
#[21] "package:datasets" "package:methods" "Autoloads"
#"package:base"
Simply use help(package="my_package") and look at the version shown.
This assumes there are no other package versions in the same .libPaths.