How to re-install a modified R package - r

Technically I have 2 probs when I tried to install a package:
1. The package can be installed normally from github by devtools::install_github, however, when I download the zip file and try to manually install it from R or RStudio, I failed. The package seems can't be installed in this way. So could somebody explain that.
2. I tried to fix some bugs by modifying the .r source codes in R directory of the package unzipped folder. Then I think I need to re-compile/re-construct the package. Could some one give me a tutorial to do that.
IOS: Windows10, 64bit; R and Rtools are both the newest.
For prob1, here is the screen capture:
Thanks.

Close R and RStudio (if applicable) and uninstall the package manually by deleting its folder from your file system
For your 2nd problem after following #1 you can reinstall it by installing from source:
install.packages(path_to_file, repos = NULL, type="source")
Please confirm that these worked for you or let me know if not.

Related

R: Error in install.packages : cannot open the connection

I was trying to install the package RINDSEL but I am unable to install it and I keep getting the following error:
Error in install.packages : cannot open the connection
I downloaded the package from:
rindsel_1.0_2.zip | Integrated Breeding Platform
and loaded it from the directory. Other packages from the directory can be installed but just not this one.
Is the package corrupt or could there be any other error?
I would really be grateful for any help. Thanks in advance
Rename the zip file RinSel Software into Rindsel. That's the name specified in the discription file.
Then, you can install the package in R with the command
install.packages("C:/path/to/Rindsel.zip",repos=NULL,type="win.binary")
That works fine... at first (!!!).
Problem with the Rindsel package is. It is quite old. It was build with R 2.13.1. Therefore, if you want to load the library which would be the next step to use the package in R you will get the error:
Problems building package (Error: "package has been build before R-3.0.0")
My suggestion: Contact the authors of the package and ask them if they can either provide the source file that you can build the package by yourself or if they can bundle the Rindsel package with a newer R version.
(Or you could try to hunt down an old R version and see if you can get the thing running with an old R... However, I would not seriously suggest to do that. It would probably result in conflicting dependencies with the other required packages...)
EDIT 15-02-2018: OP asked if one can build an R package with sources that are presumeably the Rindsel source files.
Yes, basically, you could do that. You would have to make a your own description and namespace file and put the source file in the R folder than invoke the command in R to build it....
But it's not neccessary with the script files provided by the link the OP posted.
OP, just run the scripts in R! It's quite easy.
Download the zip-file and extract it on your machine.
Go to that directory. The R command would be
setwd('path/to/your/directory')
Than run the R script, e.g, the KNIndex.r. It's simple:
source('KNIndex.r')
Then the script will run and produce some output / prompts.
For future readers,
I was able to fix the error by running RStudio with administrative privileges to get the command to work.
If that does not fix it, you might wish to try
Installing "r tools" if that is not installed already. That can be downloaded from
https://cran.r-project.org/bin/windows/Rtools/
Download a relevant package that you are trying to install (e.g., tidyverse_1.3.0.zip) from https://cran.rstudio.com/
and install that from local path
It can also be installed directly from the web using install.packages("https://cran.rstudio.com/bin/windows/contrib/4.0/tidyverse_1.3.0.zip")
I had the same problem. R was not able to extract and compile the package files to the default installation directory for some system-specific reasons (not R related).
I was able to fix this by specifying the installation directory of the package lib using:
install.packages("your package", lib = 'path/to your/required/installation/directory')
You can then load the package by specifying the lib.loc option while loading it:
library('your package', lib.loc='path/to your/required/installation/directory')
A better solution:
Create a new environment variable (if you are using windows) R_LIBS_USER with the following directory path/to your/required/installation/directory.
This will change the default installation directory of the packages and make it easier to load and install them without specifying the location everytime.

Error in R: (Package which is only available in source form, and may need compilation of C/C++/Fortran)

I'm trying to install the 'yaml' and 'stringi' packages in R-Studio, and it keeps giving me these errors:
> install.packages("stringi")
Package which is only available in source form, and may need compilation of C/C++/Fortran: ‘stringi’
These will not be installed
or
> install.packages('yaml')
Package which is only available in source form, and may need compilation of C/C++/Fortran: ‘yaml’
These will not be installed
How can I get these to install properly?
The error is due to R being unable to find a binary version of the package on CRAN, instead only finding a source version of the package and your Windows installation being unable to compile it. Usually this doesn't occur, but in this case was caused by the (temporary) outage of some of the mirrors at CRAN. If you type:
> getOption('repos')
CRAN CRANextra
"http://cran.rstudio.com" "http://www.stats.ox.ac.uk/pub/RWin"
attr(,"RStudio")
[1] TRUE
You will see that R uses "http://cran.rstudio.com" by default to look for a package to download. If you see the cran mirrors web page you can see at the top that "http://cran.rstudio.com" actually redirects you to different servers world wide (I assume according to the geo location).
When I had the above issue, I solved it by manually changing the repo to one of the urls in the link provided. I suggest you use a different country (or even continent) in case you receive the above error.
I provide below some of the urls in case the link above changes:
Brazil http://nbcgib.uesc.br/mirrors/cran/
Italy http://cran.mirror.garr.it/mirrors/CRAN/
Japan http://cran.ism.ac.jp/
South Africa http://r.adu.org.za/
USA https://cran.cnr.Berkeley.edu/
You need to run the function install.packages as follows:
install.packages('<package_name>', repo='http://nbcgib.uesc.br/mirrors/cran/')
#or any other url from the list or link
One of them should then work to install a binary from an alternative mirror.
You need to install RTools to build packages like this (i.e., a source package rather than a binary). After you install Rtools, then try again to install.packages("ggplot2") and R will prompt you with:
Do you want to attempt to install these from source?
y/n:
(see the picture below)
You need to answer y and it will try to compile the package so it can be installed.
Struggled with this issue today, solved it for now by first downloading the windows binary and then installing e.g.
install.packages("https://cran.r-project.org/bin/windows/contrib/3.3/stringi_1.1.1.zip", repos =NULL)
Just go to https://cran.r-project.org/ and then R Binaries/Windows/contrib and copy the url as argument to install.packages()
Install the package from a zip file - downloadable from the r-project website.
In basic R
go to Packages
Install packages from local files.
In RStudio
go to Packages
Install packages
Install from Package Archive File.
I had this issue when using an out-of-date version of R, so no binaries were available. The simple solution was to update my version of R.
Anything worked for me, until I found out my computer had an old version of R installed. Uninstalling everything and installing the newest R version worked!
I had to download the latest version of Rtools:
Go into the downloads folder and double click it to install it.
Close and reopen any R session.
Now packages should install like normal.
However, if you still have trouble, try installing the package from source (using type="source")
Like this:
install.packages("dplyr", type="source")

Issue installing a package in R

I'm new to R. Trying to install the package UsingR but running into problems:
library(UsingR,lib="C:\[whereitwent]")
Loading required package: HistData
Error: package ‘HistData’ could not be loaded
In addition: Warning message: In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc) : there is no package called ‘HistData’
Now when I did the install.packages("UsingR", lib="C:\[whereitwent]") bit, there was a weird part:
Warning: unable to move temporary installation ‘C:[where it went]\library\file7946ce71334\acepack’ to ‘C:\[whereitwent]\R-Portable\App\R-Portable\library\acepack’ package ‘HistData’ successfully unpacked and MD5 sums checked
I was having this same problem yesterday except instead of "there is no package called 'HistData' it was telling me there is no package called 'Formula'. I uninstalled and reinstalled R Portable this morning, tried again, and this is the result. My professor did this exact thing on her computer right in front of me yesterday and everything worked fine. I've tried this on two computers myself and it's the same issue both places. I've tried googling this but can't find anything substantive, and frankly I'm not really even sure how to google this exact issue. Can anyone help me identify the problem?
Note: "[whereitwent]" is my edit here so I'm not showing off my whole thing including my name. Everything else is copied and pasted exactly as is.
If you just want to be able to install packages, this will set library path:
.libPaths('C:/[path]')
you might need to escape the slashes, I'm sorry I don't use windows. You can add this to a file .Rprofile in your home folder and you won't have to do it again.
Alternatively (or in concert) you may want to look at the packrat package which will install packages with the project you're working on
This error is related to permissions issues, run R or RStudio as administrator (assuming you're on windows) and re-install the package.
If you are unable to run as administrator you usually will not be able to write to the C:\Program Files directory on a corporate computer. All you need to do is change the directory to which the package is installing to a folder to which you have read write permissions. For example, on my computer:
install.packages("gdata", lib = "C:/Users/mkemp6/Desktop/Rscrap", repos = "http://dirichlet.mat.puc.cl/")
To view permissions on a specific folder, right click the folder, select the "Security" tab and and highlight your username.
The same problem was solved by updating R to 3.1.3
I was experiencing similar issue on my Ubuntu machine. I solved it by running R as a "sudo" user and then install the packages from CRAN.

install cnv-seq.tar.gz in R

I'm trying to install this cnv-seq package on my R library to help copying number variation analysis. However, when I type in
install.packages("cnv-seq")
in R command, an error code pops out saying it is not available for 3.1.1 version. So I tried the old versions as well. All says not available. And I double check with the menu, Packages-> Install packages->. No cnv-seq
Ok. Then I tried to install it from a local source which is the "cnv-seq.tar.gz"
when i type in
install.packages("C:/cnv-seq.tar.gz", repos=NULL, type="source")
it still returns an error that says cannot extract package from this file.
Installation of package had non-zero exit status.
Anything went wrong or is there another I can install this package manually to my PC? After take a look at a similar question here couple years ago,
How do I install an R package from source?
I still could not fix this problem.
This is a case of RTFM ;)
You can do the whole process from within R. Below, we download the archive to the temporary directory, then extract it and finally install it.
download.file('http://tiger.dbs.nus.edu.sg/cnv-seq/cnv-seq.tar.gz',
f <- tempfile())
untar(f, exdir=tempdir())
install.packages(file.path(tempdir(), 'cnv-seq', 'cnv'), type='source', repos=NULL)
I believe you first must untar the file. I believe 7zip has this capability if you do not have access to a linux machine. The linux command would be:
tar -xvf /path/to/file/cnv-seq.tar.gz
After you do this you should be able to import the package into R.

How do I install an R package from the source tarball on windows?

The forecast package for R has been updated to version 2.12, but there are currently only windows binarys for 2.11 available on CRAN.
How do I install an R package from the source on Windows?
I know this is an old question but it came up first in my Google search for this same question, even though I knew the answer I just wanted something to copy and paste. Which makes it worth improving the answer for future reference. So here is what works for me:
Install rtools, then:
install.packages(path_to_file, repos = NULL, type="source")
Two answers that may help you avoid the hassle of installing Rtools.
Use http://win-builder.r-project.org/ to build a binary version, download it, and install (using install.packages(...,repos=NULL))
If the package has no binary component (i.e. no src directory with C, C++, or Fortran code that needs to be compiled during installation (not true for forecast, but possibly useful some other time) then simply specifying type="source" within the install.packages call (whether from a repository or a local copy of the source tarball (.tar.gz file)) will install the source package, even on Windows.
Start by reviewing the section on Windows packages in the R Installation and Administration manual, then carefully follow the instructions from The Windows toolset appendix.
I know it's usually bad form to mainly provide links in an answer, but these are links to the canonical references on this topic. I simply link to them rather than summarize their contents, since they should be accurate for the most current R release.
I'm not sure if this is the best way, but I found the following method to work (based in part on the answers above):
1) Download the package .tar
2) Move the package to the directory with your user R libraries (e.g., in my case it was "C:/Users/yourUserName/Documents/R/win-library/3.3")
3) Within Rstudio (or elsewhere, probably), run the command... install.packages("packageName.tar", repos=NULL, type="source")
That worked for me at least. Hope it's helpful!
Download the package *.tar.gz.
make sure you have Rtools installed.
Make sure the R and Rtools paths are added in the environment varialble.
Open a command prompt. Type R CMD INSTALL packagename.tar.gz.
it will work i hope.
To install a package from a .tar.gz file, follow these steps:
Launch R to have the R command prompt
Type: install.packages(<path_to_tar.gz_file>, repos = NULL)
or launch directly:
R CMD INSTALL <path_to_.tar.gz_file>
You need to have R installed but you don't need RTools

Resources