R 3.2.3 devtools::install_version() fails (.zip file not found) - r

I'm trying to leave instructions for how to set up an R environment as similar as possible to mine on Windows. I found this stackoverflow thread, which was really helpful:
Installing older version of R package
I can get most packages to work using the "versions" package, which pulls from MRAN. However, a few packages are not available on MRAN (because they were published too long ago).
So I tried to use the devtools::install_version() option. However, I have found that I get the following error:
devtools::install_version("proj4", version = "1.0-8")
#> trying URL 'https://cran.rstudio.com/src/contrib/proj4_1.0-8.zip'
#> Error in download.file(url, destfile, method, mode = "wb", ...) :
#> cannot open URL 'https://cran.rstudio.com/src/contrib/proj4_1.0-8.zip'
#> In addition: Warning message:
#> In download.file(url, destfile, method, mode = "wb", ...) :
#> cannot open URL 'https://cran.rstudio.com/src/contrib/proj4_1.0-8.zip': HTTP status was '404 Not Found'
#> Warning in download.packages(pkgs, destdir = tmpd, available = available, :
#> download of package ‘animation’ failed
By navigating around the website, I think that the CRAN no longer posts .zip files, but there is a .tar.gz file:
https://cran.rstudio.com/src/contrib/proj4_1.0-8.tar.gz
I believe that I still could install a .tar.gz file, but I don't know how to make R do it for me.
I'm hoping that someone here can help me with a solution that gets devtools::install_version() to work on R 3.2.3. (If the only solution is to install version 3.2.4, then I could probably make that work, too, but would prefer not to)
I'd also appreciate some pointers explaining how these packages are stored. In particular, it seems possible that I could just copy the folders out of my library and have someone else put them into theirs, and things will work (as long as they are also using windows(?)). Or would I have to build binaries? If so, how would I do that? This way I could have the devtools::install_version() method only as a backup.
Thanks!

When you install a package, devtools get the type from
getOption("pkgType")
To install the source version, i.e. the tar.gz file, just specify the argument
devtools::install_version("proj4", version = "1.0-8", type="source")
I'm presuming you're using Windows, so you may have to install Rtools as well.

Related

how to install install.packages("prob") in Jupyter notebook

I wanted to use Jupyter Notebook to do my homework. But when I put install.packages("prob") in Jupyter Notebook, it gave me this error:
Warning message:
“package ‘prob’ is not available (for R version 3.4.2)”
when I typed library(prob), it said no package called 'prob'
Error in library(prob): there is no package called ‘prob’
Traceback:
library(prob)
stop(txt, domain = NA)
anyone knows how to fix this problem? I would be very appreciate it.
Thank you so much.
The reason you can't install that package is exactly what it says it is :)
"Warning message: "package 'prob' is not available (for R version 3.4.2)"
If you look up the package on CRAN it will tell you:
Package ‘prob’ was removed from the CRAN repository.
Formerly available versions can be obtained from the archive.
Archived on 2017-09-11 as it depends on 'fAsianOptions', which was archived.
As that says, there are archived versions. But, to be clear, you'll need an archived version of 'fAsianOptions' as well.
To install an archived package, use:
archived_package = "a character vector with a URL or path to file you've downloaded"
install.packages(pkg = archived_package, repos = NULL)
I'd advise downloading the file yourself and then using the character vector of a path to that file as your pkg argument, unless you're familiar with the various quirks of downloading a file as part of a call to a function.

R unable to load internet routines after upgrade to MacOS Sierra

When running R after upgrading my mac to 10.12.6 (Sierra), R can no longer load libraries or access anything on the internet:
> install.packages("devtools")
--- Please select a CRAN mirror for use in this session ---
Warning: failed to download mirrors file (internet routines cannot be loaded); using local file '/anaconda/lib/R/doc/CRAN_mirrors.csv'
[...]
Warning: unable to access index for repository
https://cran.cnr.berkeley.edu/src/contrib:
internet routines cannot be loaded
Warning messages:
1: In download.file(url, destfile = f, quiet = TRUE) :
unable to load shared object '/anaconda/lib/R/modules//internet.so':
dlopen(/anaconda/lib/R/modules//internet.so, 6): Library not loaded: #rpath/libssh2.1.dylib
Referenced from: /anaconda/lib/R/modules//internet.so
Reason: image not found
2: package ‘devtools’ is not available (for R version 3.4.1)
Similarly:
> source("https://bioconductor.org/biocLite.R")
Error in file(filename, "r", encoding = encoding) :
internet routines cannot be loaded
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
unable to load shared object '/anaconda/lib/R/modules//internet.so':
dlopen(/anaconda/lib/R/modules//internet.so, 6): Library not loaded: #rpath/libssh2.1.dylib
Referenced from: /anaconda/lib/R/modules//internet.so
Reason: image not found
This happens both when I run R from Terminal and when I run R from RStudio (though RStudio only gives me the error, not the warning, and then still fails).
I found other people with vaguely similar problems in the past; one common solution was to re-install XQuartz, which I have done, but which didn't help.
Another common solution was to update LD_LIBRARY_PATH. However, 'libssh2.1.dylib' does not seem to exist: 'locate libssh2.1.dylib' returns nothing. I did find libssh2.dylib in /Applications/Xcode.app/Contents/Developer/usr/lib/libssh2.dylib, which is presumably the same thing, but R isn't finding it, I suppose.
Any ideas? Thank you!
EDIT: I found a simple solution. Just download the .tar file and use the command 'R CMD INSTALL mcmcse_1.3-2.tar', for example, in your terminal, from the directory in which your .tar file is saved.
I think that install.packages(‘package_name’) not working within R on macOS Sierra (with the package manager Anaconda installed) might be because Anaconda moves R’s path.
Just a reply to flag the same issue while using Anaconda 4.2.0 with R 3.4.1 on macOS Sierra 10.12.6. I was initially running R 3.4.0 in /usr/bin/R, but R has since become R 3.4.1 in /Users/[username]/anaconda/bin/R after installing Anaconda 4.2.0.
Warning: unable to access index for repository https://www.stats.bris.ac.uk/R/src/contrib:
internet routines cannot be loaded
Warning messages:
1: In download.file(url, destfile = f, quiet = TRUE) :
unable to load shared object '/Users/michaelfaulknerlocal/anaconda/lib/R/modules//internet.so':
dlopen(/Users/michaelfaulknerlocal/anaconda/lib/R/modules//internet.so, 6): Library not loaded: #rpath/libssh2.1.dylib
Referenced from: /Users/michaelfaulknerlocal/anaconda/lib/R/modules//internet.so
Reason: image not found
2: package ‘mcmcse’ is not available (for R version 3.4.1)
This turns out to be, as far as I can tell, a bug in Anaconda2-4.4.0-MacOSX-x86_64.pkg I had an anaconda/ directory in /, /Applications/, and /Users/[me]/: I deleted all of them, and removed the Anaconda PATH change to .bash_profile. R then reverted to /usr/local/bin/R, which did not have the internet connection problems reported above. Then I reinstalled Anaconda from scratch, then installed RStudio from Anaconda-Navigator. 'which R' now pointed at /Users/[me]/anaconda/bin/R (the PATH having changed again upon install), and which had the internet connectivity problem. Running /usr/local/bin/R directly, even with Anaconda installed, had no problems.
I've filed the bug as https://github.com/Anaconda-Platform/support/issues/137 but now can at least run R myself by using /usr/local/bin/R.

R Package installation Issue

I'm not able to install any packages in R. I tried in all versions of R starting from 3.2.2 till 3.2.4(revised), but I get the same error. It seems like a proxy issue to me as I'm connected to my college firewall. I was able to install the packages when I'm connected to my home network. Can you please guide me to resolve this issue.?
Here are the error messages
> chooseCRANmirror()
Error in download.file(url, destfile = f, quiet = TRUE) :
cannot open URL 'https://cran.r-project.org/CRAN_mirrors.csv'
In addition: Warning message:
In download.file(url, destfile = f, quiet = TRUE) :
InternetOpenUrl failed: 'The server name or address could not be resolved'
> install.packages("ggplot2")
Installing package into ‘C:/Users/HP/Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
Warning: unable to access index for repository https://cran.rstudio.com/src/contrib
Warning: unable to access index for repository
Warning: unable to access index for repository
Warning: unable to access index for repository
Warning message:
package ‘ggplot2’ is not available (for R version 3.2.2)
This is the same problem I was also facing while installing any packages. The main reason what I think is that your R session can't connect to the files path on Cran server.
What I did was just manually go to the Cran website and download the windows release for that particular package. Now unzip the files and manually paste the folder into your library folder of R.
The library folder path will be something like this:
C:\Program Files\R\R-3.2.3\library
Now go to your R console and load it with library(package name).
You can now use your package.
Simply use HTTP mirror instead of HTTPS ones.
To change mirror go to "Packages menu" -> "Set CRAN mirror" -> "(HTTP mirrors)" -> select any
Thanks for your valuable feedback guys. The solution to this problem drove me crazy. I have set my proxy settings according to my college network in MOZILLA, however, I have not set the same for IE. I guess, R downloads the packages based on IE settings, which was not configured. After setting the proxy to connect to the internet, I was able to download the packages without any issues.
Figured this out after trying all your solutions, but at last it was this silly thing that worked.
Thanks for all your time and suggestions.
you can reset and restore your internet connection (for windows and your default explorer),The problem will be solved.
To fix:
Uncheck the 'use secure download method' checkbox in Rstudio global options.
Restart internet then restart Rstudio
utils:::menuInstallPkgs()
--- Please select a CRAN mirror for use in this session ---
Warning: unable to access index for repository https://ftp.iitm.ac.in/cran/src/contrib:
cannot open URL 'https://ftp.iitm.ac.in/cran/src/contrib/PACKAGES'
Error in install.packages(NULL, .libPaths()[1L], dependencies = NA, type = type) :
no packages were specified

Install an R package directly from a URL for the package source

I would like to install a package directly from a URL for the package source. I want to do this to make it easy for people to test a pre-release version of the package which should not be widely (or permanently) available. This is a similar question but it is different because it only describes how to install from local files not general URLs.
For the sake of this question I will use a link to the boot package source. Reading ?install.packages particularly the description of the pkgs argument suggests:
install.packages(
"http://cran.r-project.org/src/contrib/Archive/boot/boot_1.3-7.tar.gz",
repos = NULL, type = "source"
)
However this fails with:
Warning in install.packages :
installation of package
‘http://cran.r-project.org/src/contrib/Archive/boot/boot_1.3-7.tar.gz’
had non-zero exit status
Suggesting that the URL is being interpreted as the package name, not its location.
We can work around this with the following two step procedure:
download.file(
"http://cran.r-project.org/src/contrib/Archive/boot/boot_1.3-7.tar.gz",
"boot"
)
install.packages("boot", repos = NULL, type = "source")
But I would prefer to do this with a single call to install.packages only; and since install.packages is capable of downloading files anyway I feel this should be possible.
install.packages now works with http URLs (not https yet) as of 3.1.1. This works for me:
install.packages("http://www.lepem.ufc.br/jaa/colorout_1.1-0.tar.gz", repos=NULL)
Edit: As of R 3.2.0, https is builtin via libcurl. This should work now:
install.packages("https://github.com/hadley/devtools/archive/v1.7.0.tar.gz",
repos=NULL, method="libcurl")
Edit: As of R 3.2.2, https should work with default options assuming libcurl support was compiled in.
Edit 2016-04-20: There may be some issues downloading packages hosted on S3, but method='wget' seems to work for those for now.
See ?install_url in the devtools package.
Why not set up the directory in which you store the source package as a repository?
Here is an example (though you'd likely want to substitute type="source" for the type="win.binary" in the code at that link).
If the url is a github repository, try: install_github()
e.g.
library(devtools)
install_github("DeveloperName/PackageName")
# e.g. install_github("cran/seoR")

Did the subdirectory structure of package repositories change as of R 2.15.2?

Kind of embarrassing / a no-go, but since it hasn't been that long that I've moved from "pure user" to "beginner-developer", I've never actually read the CHANGELOG when a new R version came out - well until today (and I have the feeling I should make this a habbit) ;-)
Yet I'm not sure if the supposed change actually occurred since I couldn't find anything about it at a first glimpse at the CHANGELOG of R R 2.15.2:
Actual question
Is it possible that the (subdirectory) structure of package repositories changed from
./bin/windows/contrib/2.xx/
to
./src/contrib/2.xx/ or even ./src/contrib?
Or at least that the PACKAGES file now needs to live here: ./src/contrib/PACKAGES?
Background info
Up to version 2.15.1, the following path worked to install packages from my local package repository:
path.repos <- "L:/R/packages"
repos <- file.path("file://", path.repos)
Function contrib.url would take repos and expand it to the right subdirectory:
> contrib.url(repos)
[1] "file:///L:/R/packages/bin/windows/contrib/2.15"
But when I try to run install.packages(), I get the following error for R 2.15.2:
> install.packages("mypkg",
+ lib=file.path(R.home(), "library"),
+ repos=repos,
+ type="win.binary"
+ )
Error in read.dcf(file = tmpf) : cannot open the connection
In addition: Warning message:
In read.dcf(file = tmpf) :
cannot open compressed file 'L:/R/packages/src/contrib/PACKAGES', probable reason 'No such file or directory'
>
When I do the same with R 2.15.1, everything works smoothly.
Due dilligence
There are some references with respect to repositories in the CHANGELOG, but the only section I found that gives me some evidence that the supposed change occurred is this:
PACKAGE INSTALLATION
For a Windows or Mac OS X binary package install, install.packages() will check if a source package is available on the same repositories, and report if it is a later version or there is a source package but no binary package available.
Just had a look at the official documentation again and got the idea that maybe arg type is not passed along to contrib.url() correctly as it seems to me install.package() is looking at the place for type="source" packages?
This particular bug isn't the same as mine.
This issue relates to checks install.packages() now runs before installing. As Rappster said, it tries to find a source package to compare the binary version with:
For a Windows or Mac OS X binary package install, install.packages() will check if a source package is available on the same repositories, and report if it is a later version or there is a source package but no binary package available.
So a simple way of squashing this message is creating the R/src/contrib directory and running tools::write_PACKAGES() in that directory to create (an empty) PACKAGES file.
And of course, the reason you aren't getting this message in 2.15.1 is that it doesn't do the checking (see R NEWS quote above) that 2.15.2 performs.
I have submitted a bug report of my issues. No news yet. May post it to the R mailing list as well.

Resources