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

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!

Related

how can fix this issue "Error in h2o.upload_model() : could not find function "h2o.upload_model"?

I have installed h2o package(in R from RStudio console). Post h2o.init() I am trying to use the built in function upload_model()/upload_mojo() but I am getting following error.
h2o.upload_mojo()
Error in h2o.upload_mojo() : could not find function "h2o.upload_mojo"
h2o.upload_model()
Error in h2o.upload_model() : could not find function "h2o.upload_model"
I found work around to resolve this issue. Please find below the steps I followed:
Remove the package using: remove.packages("h2o")
Quit the current session and launch the new one.
Move out lock file for h2o from path where package was installed mostly under R with file name like - 00LOCK-h2o
Install new/latest version of package via RStudio console using install.packages()
It should now resolve this issue.

Unable to run Papaja in Windows due to spaces in folder name

I'm trying to load papaja in R (version 3.6.0). I'm running Windows 10 on my computer. When I try to run devtools::install_github("crsh/papaja") I get the following error message:
package ‘markdown’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\My
Name\AppData\Local\Temp\RtmpKCmBDG\downloaded_packages
ERROR
cannot change to directory 'C:\Users\My'
The system cannot find the path specified.
Error in (function (command = NULL, args = character(), error_on_status =
TRUE, :
System command error
From some research, including this post and this post, I realise that this is a common issue, but none of the answers I can find help me work around this in papaja.
For info, I don't have this problem when installing other packages using install.packages().
I have managed to solve this problem after hours and hours of googling. The problem is not papaja; it is the presence of spaces in the path, which devtools does not deal with well.
To solve this, I first changed my library path:
.libPaths("C:/Program Files/R/R-3.6.1/library") # for R v.3.6.1
At first I couldn't get this to work - I kept getting the error 'lib = "C:/Program Files/R/R-3.6.1/library"' is not writable. Basically, this is because I did not have permission to write into this folder. To fix this, you simply close RStudio, go to the folder where the programme is saved and right click, then select 'Run as administrator'.

How to input R package from local PC directory

I need to use a package from Hogg's Introduction to Mathematical Statistics text. It is not found on cranR. R input follows below. Package is in 3.5 directory.
library(hmcpkg, lib.loc="C:/Users/mmsta/Documents/R/win-library/3.5")
Error message:
Error in library(hmcpkg, lib.loc = "C:/Users/mmsta/Documents/R/win-library/3.5") : ‘hmcpkg’ is not a valid installed package
How to do without going to Hogg website when I have the directory hmcpkg on my hard drive? This is a generic question; I have encountered this before. I would also like to avoid the complexity of github.
Thanks.
Mary A. Marion

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.

Resources