Anaconda R environment can't access libraries/packages when in R project of github repository - r

I have an R environment in Anaconda with all the packages I need and use. I added a private repository from github onto my pc using the conda CLI. The project files includes an renv folder as well a .Rproj file. When I try to open any of the R scripts in the project without opening the Rproj file to open the project, they all show up as blank, and when I try to open a csv file it says it doesn't exist. When I open the Rproject, I cannot access any of my libraries or packages that I usually have access to in R. When I tried to install a package in this environment, I got the error:
warning in system(paste(cmd, "shlib-clean")) : 'make' not found warning in system(cmd) : 'make' not found error: compilation failed for package 'pkgload' * removing 'c:/users/poona/<repo name>/renv/staging/1/pkgload'
What's going wrong? I just want to access the scripts of the repository and load the packages of my usual environment. Any help is appreciated!

Related

lazy-load database '../R/NymbulCredentials.rdb' is corrupt

I am trying to install a package from GitHub in support of deploying an app to shinyapps.io. If I download the package onto my machine, then it installs without issue. However, if I execute the command (in RStudio):
devtools::install_github(repo="rlmoore0/NMDeploy", subdir="NymbulCredentials")
then I get an error message: Error in (function (n) :
lazy-load database '../R/NymbulCredentials.rdb' is corrupt
This GitHub repo is public, so anyone can try running this command from within R/RStudio with devtools installed. I am on a Windows box running R 3.6.3, Win10.
Any suggestions?
I have looked at questions from other people with similar problems and based on the responses to them, I have tried:
Closing and restarting R/RStudio
Executing the command devtools::unload("NymbulCredentials")
Executing the command unloadNamespace("NymbulCredentials")
Removing the installation library the package is being installed to as referenced by .libPaths() and trying a fresh directory as the installation location.
The error still persists.

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.

offline installation of packages in R - empty index file generated

I am trying to install packages on a remote windows machine with no internet connection using source packages. I am trying to follow the instructions given in an answer to the previous question
Offline install of R package and dependencies
I have a folder with .tar.gz files for the package and it's dependencies. I run the commands
library(tools)
write_PACKAGES()
which generates the PACKAGES and PACKAGES.gz in the same folder. However, my PACKAGES file is empty (with size 0 KB).
When I try to install the package using
install.packages("<PACKAGE_NAME>", contriburl = "file:///")
(I am in the same directory as all the source files), I am getting the following error
cannot open compressed file '//PACKAGES', probable reason 'No such file or directory'
I am not sure if there is something wrong with the way I specify the path or is it because my PACKAGES file is empty that I am getting this error.
Any help here would be great!
Additional info - The remote machine is a Windows machine and I have also tried deleting the PACKAGES.gz file before installing (as recommended in the link above), but did not succeed.
Thanks!
SN248
I was able to install the package that I wanted (package name = dplyr), using the hints in the comments above. I needed to change two things
I downloaded windows binaries instead of source files, using type = "win.binary" parameter in the download.packages command.
The path in contriburl = "file:///" needed to be changed to contriburl = "file:///<ABSOLUTE_PATH_TO_FOLDER_WITH_WIN_BINARIES>"
With these changes, the package installation went successfully.
Hope it helps others.
SN248

Installing gdata in R

I tried to install package gdata with the following command, but got the message that follows:
install.packages(pkgs="gdata")
Warning in install.packages(pkgs = "gdata") :
'lib = "C:/Program Files/R/R-3.1.3/library"' is not writable
Error in install.packages(pkgs = "gdata") : unable to install packages
Seems the directory "library" should be writable, so what did I do wrong?
You can install in a custom folder by specifying the lib argument of install.packages. Try something like lib = "C:/Users/you/Documents/R/3.1.3/" or whatever folder you have writable.
If R is installed on a Remote Desktop, or somewhere else where R is having difficulty automatically installing those folders, you will need to specify where to put the files. The first step will be creating these folders, for example in your C:/ or D:/ drive. Preferably create an R folder, with a version folder (3.1.3) that you will be using. To know which version of R your using if using R studio, hold control while opening R studio.
Once these folders are created, just use the following code, inputting your path to the version folder (3.1.3). For example:
lib = "D:/R/3.1.3"
install.packages("gdata", lib)
And then to load your package.
library("gdata", lib.loc= lib)

How to install a package not located on CRAN repository?

I am trying to use Google Trends data and have come across a few packages that are not on CRAN (GTrends, RGoogleTrends).
I like what I have seen from the RGoogleTrends package at this blog, and wanted to give it a try. The RGoogleTrends package is located here: http://www.omegahat.org/RGoogleTrends/
First of all, I am using a Windows OS and there is an uption in my R console:
>Packages>Install package(s) from local zip drives ...
This results in the following:
> utils:::menuInstallLocal()
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 'RGoogleTrends_0.2-1.tar.gz/DESCRIPTION', probable reason 'No such file or directory'
I'm guessing this has to do with the fact that the file is as a .gz and not a .zip file.
So, I unzipped the .gz file outside of R and then zipped it into a .zip file (there's got to be a better way). Now I can install the .zip file, but when I try and load it with library, the following error occurs:
> library(RGoogleTrends)
Error in library(RGoogleTrends) :
‘RGoogleTrends’ is not a valid installed package
What am I doing wrong here?
You will need R version 3 for this, which you can get here for example:
http://cran.cnr.berkeley.edu/bin/windows/base/R-3.0.1-win.exe
Then open R and type:
install.packages("devtools")
require(devtools)
install_url("http://www.omegahat.org/RGoogleTrends/RGoogleTrends_0.2-1.tar.gz")
require(RGoogleTrends)
ls("package:RGoogleTrends")
You may get few warnings in the process. Ignore them. you should then be able to use the package.
I think a package builds differently for linux than to windows so a .gz version can't be converted to .zip
This link indicates you should be able to use just the unzipped version...
http://decisionstats.com/2013/04/26/using-a-linux-only-package-in-windows-rstats/
The comment in it suggests devtools or Rtools, both of which will allow direct installation from the gz file
To unzip and use directly
Extract from tar.gz to .tar
Extract from .tar
Set the working directory to the R subfolder e.g. Setwd( "C:\\Users\\x\\Documents\\RGoogleTrends_0.2-1.tar\\RGoogleTrends_0.2-1\\RGoogleTrends\\R")
Load all functions for (i in list.files()){source(i)}
To use devtools
Install devtools
library("devtools")
Setwd to folder containing .tar.gz file
install("RGoogleTrends_0.2-1.tar.gz")
To use Rtools
Download correct version from http://cran.r-project.org/bin/windows/Rtools/
Install from the .exe
Check whether you need to anything in http://cran.r-project.org/bin/windows/Rtools/Rtools.txt
Run R from your command line (cmd into search in start) - see
Setwd to folder containing .tar.gz file
R CMD INSTALL *.tar.gz
My preferred approach is devtools
I was having all sorts of issues with errors like:
not supported in current version
cannot find DEPENDENCIES
cannot unzip
If you are running windows and installed for all users and are running as a normal user (which you should be for all sorts of reasons) installing packages is interesting.
What I ended up doing was
close R
open R as admin
load base package
I had already downloaded the packages so I could install offline and they were in f:\software\rcontrib
then run:
files=list.files(path="f:/software/rcontrib",pattern="*.zip",include.dirs=TRUE)
for (i in seq(along=files)){install.packages(files[i],repos=NULL)}
This will bulk load packages from the local directory / common file share / non-internet location.
Then you can exit R. Running as any user on the machine you should be able to use the packages.
This will hopefully save people the couple of hours I wasted trying to bulk load and overcome errors in R which were actually windows security.

Resources