R set up local package repository - r

I'm trying to set up a local repository on my local network, following these instructions : Creating a local R package repository.
And I'm getting the same problem as the one described in the "Update" paragraph of : install.packages errors: Troubleshooting local repo usage,
(Even if the question is marked as solved, there is no available solution provided)
I've put my package into the folder:
"S:/outils/packages R/bin/windows/contrib/3.2"
As per Dirk's instructions in this SO, I've run the following commands:
setwd("S:/outils/packages R/bin/windows/contrib/3.2")
tools::write_PACKAGES(".", type="win.binary")
list.files()
[1] "BayesTree_0.3-1.3.zip" "Epi_2.0.zip" "PACKAGES" "PACKAGES.gz"
I ran the following command in order to point to my new local repository. I copied and pasted this command from the repo paragraph of the options help page :
local({r <- getOption("repos"); r["CRAN"] <- 'file://S:/Outils/packages R'; options(repos = r)})
And when I try to install some packages I get an error :
install.packages("Epi")
Warning in install.packages :
cannot open compressed file 'S:/Outils/packages R/src/contrib/PACKAGES', probable reason 'No such file or directory'
Error in install.packages : cannot open the connection
I tried to put the "PACKAGES" and the "PACKAGES.gz" files into the S:/outils/packages R/bin/windows/contrib/folder or into S:/outils/packages R/, without any success.

If you read to the bottom of Dirk's answer, you'll see he mentions the wonderful drat package. This takes care of the pain you're experiencing and creates the PACKAGES.gz file and associated paths pain free.
As a bonus, drat ties in with github.io free of charge.

Related

How do I edit an R package from GitHub that has already been cloned?

I have an R package, created by someone else that I have been made a collaborator on, that I want to work on and develop. I've already cloned the repository to my local computer through the Create Project > Clone from GitHub route in RStudio, and since then I've been editing the scripts, but not working with it as a package. As in, I had been adding functions and working on a Shiny interface, but not following any R package development rules (loading packages directly into the .R files, not updating the NAMESPACE, using roxygen2 conventions, etc.).
Everything I've read mentions devtools::install_github, but I don't want to install and use it, I want to edit it like I've been doing. I also want it to still be connected to Git (so I can continue to commit and pull from the remote server, once my collaborators make edits). I've tried devtools::load_all() and devtools::document(), but it gives me this warning:
Error in FUN(X[[i]], ...) :
bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning messages:
1: In readChar(con, 5L, useBytes = TRUE) :
truncating string with embedded nuls
2: file ‘file_example.rda’ has magic number 'X'
Use of save versions prior to 2 is deprecated
Do I need to delete my local copy and do something different to work with it as a package so that the functionality of roxygen2 and the NAMESPACE documentation will work correctly? Or is there an obvious reason for this error/something I'm missing about how to work with it as a package, how it is currently?
Thanks!
It looks like file_example.rda is corrupt
Can you just load it in R and check what it contains?
You could try:
tools::resaveRdaFiles( 'file_example.rda', compress='xz' )
And see if that saves it in a way that is acceptable?

install.packages function does not recognize new library path in RStudio

I am connecting remotely to a work server and need to be able to install R packages via RStudio. I have read through other questions/answers on this topic, but haven't been able to solve this for myself. I think the following input and output shows my issues the best: (edit: I do not have admin powers, but can call IT as last resort)
>.libPaths("C:/RWorkSpace") #setting new file path
>.libpaths() #testing
[1] "C:/RWorkSpace" "C:/Program Files/R/R-3.4.1/library"
>install.packages("bibliometrix", dependencies = TRUE, lib="C:/RWorkSpace")
The downloaded source packages are in
‘C:\Users\cortiz\AppData\Local\Temp\7\RtmpOsVuTB\downloaded_packages’
>library(bibliometrix)
Error in library(bibliometrix) : There is no package called 'bibliometrix'
>installed.packages()["bibliometrix","C:/RWorkSpace"]
Error in installed.packages()["bibliometrix","C:/RWorkSpace"] : subscript out of bounds
I just need to download the package and dependencies, and I expected them to be downloaded to the folder I specified ("C:/RWorkSpace").
very new to working with R in general so please bear with me. Any help greatly appreciated!

R installed.packages() randomly stopped working on windows 7

installed.packages() command in R lists your installed packages. Mine was working for almost a year and then this command randomly started throwing an error. As this is a built-in command, I am not even sure how to "reinstall" it or address this. Any ideas how to fix the error and get the command working again?
> installed.packages()
Error in gzfile(file, mode) : cannot open the connection
In addition: Warning message:
In gzfile(file, mode) :
cannot open compressed file `'C:\Users\Mitch\AppData\Local\Temp\Rtmp6Dawpa/libloc_190_4464fd2b.rds', probable reason 'No such file or directory'`
One suggestion on here involved this in combination:
.libPaths()
installed.packages(lib.loc = 'my path')
The results of this produced yet another error as shown here. Looks like an issue with the installed file still but how to address is the question:
> installed.packages(lib.loc = 'C:/ProgramFilesCoders/R/R-3.3.2/library')
Error in gzfile(file, mode) : cannot open the connection
In addition: Warning message:
In gzfile(file, mode) :
cannot open compressed file 'C:\Users\Mitch\AppData\Local\Temp\Rtmp6Dawpa/libloc_190_4464fd2b.rds', probable reason 'No such file or directory'
>
That is odd.
What version of R are you running, standard R or Microsoft R? And did you recently update?
If you did recently update, perhaps your packages did not get copied over, hence the 'No such file or directory' statement.
If you haven't updated, I would install a newer version and see if it fixes the issue.
If your uncertain, you can always use the updateR function to check if you have the latest version and choose to install it or not.
library(installr)
updateR()
Good luck,
I think the issue lies in terms of the where the function is looking for the package information. installed.packages() needs an argument lib.loc.
From official documentation
lib.loc character vector describing the location of R library trees to search through
Looks like the function for some reason is looking in AppData\Local\Temp which is the download location and not the installed location.
Without looking at your R_Home and .libPaths() is difficult to nail down where the problem is, however running .libPaths() should give you one or more paths as shown in the below example. None of these should be temp locations.
>.libPaths()
[1] "C:/Users/UserName/Documents/R/win-library/3.4"
[2] "C:/Program Files/R/R-3.4.0/library"
If not, you can set the path within the .libPaths("your path") or pass the path of the library as part of installed.packages(lib.loc = 'your path') and try again.
Sometimes the most simple obvious solution is what works:
I closed my RStudio environment saving it to .RData
I re-opened RStudio and tried the command again
it worked
For the future, some good ideas got posted on here before I thought to try the above. Here are the suggestions that others included in case the above does not work if this problem is encountered by anyone in the future:
Use .libPaths() to find out proper path where this is installed, and then re-run the command with the path included in it like so: installed.packages(lib.loc = 'your path')
Try debugging it with: debug(installed.packages); Expectation is that we will likely find something wrong with .readPkgDesc(lib, fields) while stepping through debug. This was not tried yet so you may encounter things not written up here when you do try it.
Try Updating R in case it is out of date with these commands: library(installr) and updateR().

RStudio Required Package Versions Could Not Be Found

I updated my Mac to OS10 and attempting to run RStudio Knit, and get the error:
"evaluate 0.7.2 is required but 0.7 is available".
I tried this and did not fixed the issue:
remove.packages("evaluate")
install.packages("evaluate")
Any help would be appreciated.
Try setting up the below option and by rerunning the code.
getOption("repos")
options(repos = c(CRAN = "https://cran.rstudio.org"))
It also happened to me. I downloaded evaluate zip file from here https://cran.rstudio.com/web/packages/evaluate/index.html
and then manually installed it in R Studio (Tools-InstallPackages-zip file).
Good luck !
install.packages('evaluate')
Warning in install.packages :
unable to access index for repository HTTP://cran.rstudio.com/bin/windows/contrib/3.4:
cannot open URL 'HTTP://cran.rstudio.com/bin/windows/contrib/3.4/PACKAGES'
When you compile the update or remove sentences, if the output like this, you could make some settings, since maybe the problem is your internet. Follow the steps:
Open Rstudio.
Click tools.
Choose global options->packages.
Modify CRAN to the country you living. like, China or Japan. Cause your browser maybe work only you do this.

Installing packages onto R

For some reason I am suddenly not able to install packages in R (I have subsequently updated to the latest version of R and am running Windows 7). For example, if I type:
install.packages('beeswarm')
Installing package into ‘D:/Rlibs’ (as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session --- trying URL 'http://www.stats.bris.ac.uk/R/bin/windows/contrib/3.0/beeswarm_0.1.5.zip'
Content type 'text/html' length unknown opened URL downloaded 1859
bytes
Error in read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package",
"Type")) : cannot open the connection In addition: Warning
messages: 1: In unzip(zipname, exdir = dest) : error 1 in extracting
from zip file 2: In read.dcf(file.path(pkgname, "DESCRIPTION"),
c("Package", "Type")) : cannot open compressed file
'beeswarm/DESCRIPTION', probable reason 'No such file or directory'
I have read that in Windows 7 there can be important restrictions on rights to writing to certain folders etc. so I've gone to some lengths to install R and library folders in non-default areas of my computer, and to allow myself rights to certain folders, but to no avail. Possibly also of importance is when I type:
.libPaths()
# [1] "D:/Rlibs"
# [2] "C:/Users/L.Halsey/Documents/R/win-library/3.0"
# [3] "C:/Users/L.Halsey/Documents/Documents/R-3.0.1/library"
I have created several folders in an attempt to create one that I could successfully install libraries into and set them up to be recognised by R using 'environment variables' from the start button. I don't know how to delete any of them though - not sure if this is relevant to my overall problem of not now being able to install/update packages for some reason.
The error being reported is inability to open a connection. In Windows that is often a firewall problem and is in the Windows R FAQ. The usual first attempt should be to run internet2.dll. From a console session you can use:
setInternet2(TRUE)
(You are correct in thinking this is not due to your library setup. The error says nothing about permissions.) I don't think just typing .libPaths should return that character vector since on my machine I would need to type .libPaths() to see something like that. If you wanted to reduce the number of places for libraries you can use the .libPaths function for setting the values. This would pick the second and third of the existing paths
.libPaths( .libPaths()[2:3] )
The inner call retrieves the path vector and the outer call sets it to a reduced vector.
Running RStudio as administrator fixed it for me!
I will probably duplicate a lot of other answers on the stackoverflow, but I got exactly the same error as OP, namely:
Warning messages: 1: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file 2: In read.dcf(file.path(pkgname, "DESCRIPTION"), c("Package", "Type")) : cannot open compressed file 'zoo/DESCRIPTION', probable reason 'No such file or directory'
Turned out, while I as a user had permissions to write in a certain directory, R did not. In order to be sure you don't have something similar, do following:
get a usb drive, let's name it E
download package source as a .zip file and store it onto usb-drive in some directory, let's name it E:/source
Create directory for libraries on the usb drive, let's name it E:/libs
Install packages calling R command install.package from the R console and setting all relevant directories to point to your usb drive:
(here I use package zoo as an example)
install.packages("E:/source/zoo_1.7-12.zip",
destdir = 'E:/source', # no "/" after the path
lib = 'E:/libs',
repos = NULL)
Load the package from the directory, where you installed it:
library('zoo', lib.loc = 'E:/libs')
After you are sure, it works this way on your usb drive, you can start resolving directories permissions, and try out by changing the paths in the code above.
update:
In some windows environments even your usb-stick might be protected from read-write by the R. Make sure you check the permissions using the machine you are working from.
The following worked for me (based on the answer above)
install.packages("clustvarsel", lib = "C:/Users/dnentchev/My Programs/R-3.2.2/library")
I had the same problem. I turned the windows firewall off, and Run RStudio as administrator. so, that error fixed.

Resources