Use different versions of packages in R - r

I am reading a book published in 2019 that uses a package (JWileymisc) that has been updated and some of the functions are deprecated, so I am spending too much time trying to update the examples. The authors use checkpoint package but I have not been able to make it work in my laptop (I don't have full rights and could not install R version 3.5.1).
I installed the older version of the package it is used in the book but I still get error message saying the functions could not be found. Is there a way around it without checkpoint and this old version of R? Or is it possible to call a function from an old version of a package? I am using Windows, by the way.
Thanks! :)

Related

R not loading packages on some MAC versions

I am using the regular R console on a MAC Air with Monterrey as the OS and I'm still having issues loading packages. It is iffy, as to whether a package is loaded and ready to use. Sometimes packages will load and sometimes not. Also, it would not call up data sets that as a default are included in the R packages I'm trying to use. the weird thing is it would recognize the example dataset that is included because when I first tied to call them up, it would let me autocomplete the name. Then it stopped doing that. Then it started telling me that the file doesn't exist. I know I haven't used R in a while but this just seems buggy! any help would be appreciated.
The R version that I have installed is : R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics" and it was installed just last week.
It seems R was not properly installed on your machine.
Several persons reported that using the package manager in RStudio actually did the trick of updating the packages.

R package listed on CRAN but not in available package

I want to install a package that is listed in https://cran.r-project.org/web/packages/available_packages_by_name.html as available in CRAN, but when I check in R the install packages menu or the available.packages() command, I can't see the package there.
Do I need to do something different to install those packages? Why aren't those packages available?
The packages I'm interested on are WikipediR ( https://cran.r-project.org/web/packages/WikipediR/index.html ), WikidataR and WikipediaR.
If it matters, I'm using R 2.15.0 in Windows XP.
See the documentation for ?available.packages...
By default, the return value includes only packages whose version and
OS requirements are met by the running version of R, and only gives
information on the latest versions of packages.
In other words... your R 2.15 is likely too old for the package you are looking to download.
You can try to download the package source manually add the package to the package library usually found somewhere like "win-library/2.15/" but like Cory mentioned it is likely that the older version of R does not support the package build.
The advice given so far is a bit incomplete although I do agree you need to update your R version if you want to use these packages. Looks like they don't need compilation so you might have been able to either install from a local copy or drop R code in, but critically they depend on httr which requires R 3.0.0 or above. They were released only relatively recently, so there will be no Windows binaries from back in 2012. (Your copy of R is from 30-Mar-2012.) Look in the DESCRIPTION file which is presented in a nice web format at the CRAN/package listing:
https://cran.r-project.org/web/packages/WikidataR/index.html
Imports: httr, jsonlite, WikipediR
Suggests: testthat, knitr, pageviews
# only one version of these two
https://cran.r-project.org/src/contrib/Archive/WikidataR/WikidataR_1.0.0.tar.gz
https://cran.r-project.org/src/contrib/Archive/WikipediaR/WikipediaR_1.0.tar.gz
# pick one of these
https://cran.r-project.org/src/contrib/Archive/WikipediR/

Clarification needed for different approaches to updating R on a mac (and keeping packages)

For over a year now, I've been afraid to update my version of R for fear of losing the "rgdal" package...which when I first started working with R on my mac (and maybe still?), had to be installed from source/ could not be installed via the package installer from within R. That was complicated and I had to seek help from a more experienced R user than myself in order to get this package which is critical for me.
But I've finally decided that I need to take the risk and update R. I used the following instructions:
#--run in the old version of R
setwd("C:/Temp/")
packages <- installed.packages()[,"Package"]
save(packages, file="Rpackages")
Followed by this in the new version:
#--run in the new version
setwd("C:/Temp/")
load("Rpackages")
for (p in setdiff(packages, installed.packages()[,"Package"]))
install.packages(p)
found in this post:
Painless way to install a new version of R?
This seems to have worked (e.g. I can open up libraries that aren't included in the base install...including rgdal) but I have the following questions in order to better understand this whole process:
1) Is it the case that in following this approach, I essentially saved a list of all the R packages I had previously installed in my old version, then (from within the new version) determined the SET of packages that differed from the set of base libraries in the new version and told R to install packages belonging to this SET?
2) If the above is true, then does this approach negate the need to update my packages after (e.g. by installing them from within the new version, the newest versions are installed)?
3) The other approach that seems to be common out there (and that is recommended in one of the responses to the post above) is to set up things so that all packages get saved to a directory outside of R and then change the settings (in the .Renviron file or whatever the appropriate file is) to always look for packages in this external directory... I'm wondering why this approach is favoured by some people? Is it because this approach means that after updating R everything is just ready to go (e.g. if one is willing to work with un-updated packages)? I'm confused because if one still has to use update.packages() after installing a new version of R, doesn't this just more or less amount to re-installing them? What are the advantages?
4) Are there packages that I need to worry about if I do go the install route (and not the save to external directory then update route)? R did give me a warning that indicates that four of my packages are not available for the latest version (R. 3.0.3). I'm assuming that if I need to use these packages, I must temporarily just revert to an older version of R. Is this all correct?
Thank you in advance for the help!
1) Yes.
2) The newly installed packages will be at the latest version, but there is no harm in running update.packages(ask=FALSE, checkBuilt=TRUE) afterward just be be sure everything is up to date.
3) I've not seen anyone suggest this particular approach, though a similar process is suggested in the R for Windows FAQ that consists of 1) installing the new version 2) copying the packages from the library folder of the old version to the library folder of the new version and 2) running update.packages(checkBuilt=TRUE, ask=FALSE). I don't think there are any clear advantages to doing it this way vs. the installed.packages()... way.
4) All methods under discussion are limited to CRAN packages, so things that you installed from e.g., bioconductor will not be covered. Also packages removed from CRAN will not be covered, you will either have to use an older version of R or build and install them manually.

calling R (2.15.3) from within R (3.0.2)

I would like to be able to call R (2.15.3) from within R (3.0.2). In order to use a package (windows binary, not on cran) that is available in only the older version of R. Is this possible?
This is R. There is no if, only how
said Simon Blomberg.
You could call an older version of R using system() and the appropriate hacks in your OS. Which is something odd to do, and opens tons of possibilities for serious damage to your computer when you hit it in frustration.
Or you could download the source of the package and rebuild it in R 3.0. There's been some rather drastic internal changes in the way packages are built and used in R (the most obvious being the removal of support for packages without a namespace).
Hence :
if the package does not have a namespace: download the source (.tar.gz), read the manual "Writing R extensions" if you didn't before, and add a namespace file with the usual exports. As explained in Writing R extensions, this can be as simple as adding a single line
exportPattern("^[^\\.]")
if the package has a namespace, build from source on your machine and you should be good to go. This is simply done by using:
install.packages("path/to/package.tar.gz",type="source")
Note that if you want to install from source on a Windows machine, you'll need a compatible version of Rtools : http://cran.r-project.org/bin/windows/Rtools/
If you don't want to be bothered with it, mail the author/maintainer of the package and kindly ask if they'd like to rebuild it for you.

How to keep using R version 2.x and download packages automatically with install.packages() by package name?

My work setup relies heavily on rcom library, which is so far unavailable for R 3.x (due to licensing problems).
I'm happy to keep using the R v. 2.15.3, but the install.packages doesn't fetch new packages anymore.
Is there any way of making old R download packages on demand with something like install.packages("MASS")?
OK, this is the fallback solution:
We can always download (windows) old packages from this location on the CRAN site and unpack the ZIPs into C:\Program Files\R\R-2.15.3\library or equivalent. But it would be cool to use some form of simple R command for doing it.
It is also possible to try using different mirrors, because mirrors are not equivalent with respect to volume of archives.
At least this is how I do it on (virtual) Windows XP 32 bit.

Resources