Installing R package from the source
First of all, I highly recommend checking my other post if you are getting package ‘xxx’ is not available (for R version x.y.z)” warning.
You are still with me? OK, let’s continue.
First of all, you need to install the package. Find your package you want to install on cran-r website.
Usually, you can find the tar balled source file on package’s page (highlighted on the image below).
Simply right click and copy the link address. And do this in your shell.
wget https://cran.r-project.org/src/contrib/your-package.tar.gz
Once it is downloaded, you need to untar with the following command.
tar -zxvf your-package.tar.gz
This will unpack the content of the tar ball, and place it in the directory you are in.
If it is a properly packed tar, you’ll find your R functions in package-name/R folder.
Now you can simply source the content of the R folder, I have a code to read and source the content of R recursively. I remember I found this code online very long time ago. So credit goes to “Anonymous”
run R on your shell, or open R studio. And copy/paste the code below.
sourceDir <- function(path, trace = TRUE, ...) { for (nm in list.files(path, pattern = "\\.[RrSsQq]$")) { if(trace) cat(nm,":") source(file.path(path, nm), ...) if(trace) cat("\n") } }
And then,
sourceDir('your-package/R')
This will automatically read the content of R folders and source the individual files recursively for you.
A word of caution, If you downloaded a package that requires compiling first (e.g. written in C++), those steps might not be able to work. I will try to address this issue later on.
Feel free to comment your experience or problem below. I would love to read and answer them all.
[…] still have problem installing the R package? See my other post […]
A-MAZING. I was about to give up
Thank you!
No problem. I am glad it worked…
Thank you sir. But when I run the command for my package in R
“tar -zxvf your-package.tar.gz”
This shows the following error
Error: unexpected symbol in “tar -zxvf ggplot2_2.2.1.tar.gz”
Could you please reply that I can I correct it.
Hi Deepika, Probably it is caused by a white space or weird characters when you copy and paste it in your terminal. Can you actually try typing directly on your terminal?
I wrote this exact statement:
“wget https://cran.r-project.org/src/contrib/rgdal_1.2-8.tar.gz”
But even I get the error ‘Error: unexpected symbol in “wget http”‘
Can you try using quote
"
or'
like
wget "https://cran.r-project.org/src/contrib/rgdal_1.2-8.tar.gz"
this is not working for me either
Thank you for the post. Any ideas for when the package is out of date, and hence not available on CRAN R?
You can pretty much do the same thing with any R packages. They do not have to be hosted on CRAN R. Am I missing something?
What am I doing wrong? I am trying to install prophet but it doesnt seem to be working. This is how I typed in the code, is there an error in it?
> ‘https://cran.r-project.org/web/packages/prophet/index.html’
[1] “https://cran.r-project.org/web/packages/prophet/index.html”
> ‘tar -zxvf your-package.tar.gz
+ ‘
[1] “tar -zxvf your-package.tar.gz\n”
> sourceDir
> sourceDir(‘prophet’)
> library(prophet)
Error in library(prophet) : there is no package called ‘prophet’
why do not you try installing it via install.packages?
Hi, thank you for this and previous posts.. they have been helpful to me and my colleges. I followed your instructions from the “INSTALLING R PACKAGE: FIXING PACKAGE ‘XXX’ IS NOT AVAILABLE (FOR R VERSION X.Y.Z)” WARNING?” post and ended up here because I was still having an issue. I am not finding the ‘libcurl4-openssl-dev’ for R 3.5.2 on the package list at CRAN. Please let me know if you find a way around this for the most recent R:
> install.packages(“libcurl4-openssl-dev”,repos=’http://cran.us.r-project.org’)
Installing package into ‘/home/realseq/R/x86_64-pc-linux-gnu-library/3.5’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘libcurl4-openssl-dev’ is not available (for R version 3.5.2)
libcurl4-openssl-dev does not sound like an R package. But it is a ubuntu package and can be installed via libcurl. Let me know if I can help more.
package ‘RTextTools’ is not available (for R version 3.5.3)
Seems like it is removed from the CRAN. You have to install from source manually. https://cran.r-project.org/web/packages/RTextTools/index.html
I have resolved the issue please check my answer on GIT
https://stackoverflow.com/questions/8382599/problem-when-installing-rtexttools-for-r/55243370#55243370
Having same trouble with quantstrat in R version 3.6.0: Warning in install.packages :
package ‘quantstrat’ is not available (for R version 3.6.0). Tried all of the above. Any new workarounds?
Please try this https://stackoverflow.com/a/45194944
> install.packages(“Seurat”)
Warning in install.packages :
package ‘Seurat’ is not available (for R version 3.6.2)
Warning in install.packages :
unable to access index for repository https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6:
cannot open URL ‘https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/PACKAGES’
> install.packages(“Seurat”, repos = ‘http://cran.us.r-project.org’)
trying URL ‘http://cran.us.r-project.org/bin/macosx/el-capitan/contrib/3.6/Seurat_3.1.2.tgz’
Content type ‘application/octet-stream’ length 3202077 bytes (3.1 MB)
==================================================
downloaded 3.1 MB
The downloaded binary packages are in
/var/folders/zb/5qbgts5n5rs_fj0zfg978zjc0000gn/T//RtmpzjQAnr/downloaded_packages
Anyone can help me? many thanks
Can you print more of the errors you see in your end… I think once you use repos, it seems to be running.
I am trying to MCMCglmm package of R. However, I have faced technical error to ordering the pedigree. So far, even though both MasterBayes and pedantics are removed from CRAN, I tried to install the latest archive of both packages but both of them were not integrated to my R v.3.6.1. Software.
Could you please let me know how to install it.
you can install the packages in your local directory and load them like this `library(packageName, lib.loc = “/paht/for/the/local/package/dir”)`