Installing packages to R from desktop - r

I am trying to install several packages to R. The packages were send to me via email from my biostatistician and I have them on my desktop in a file called R_scripts.
I have tried:
install.packages("/Users/isimee/Desktop/R_scripts/findalpha.R", repos=NULL, type="source")
Which returns following error message:
Error in untar2(tarfile, files, list, exdir, restore_times) :
incomplete block on file
Warning message:
In install.packages("/Users/isimee/Desktop/R_scripts/findalpha.R", :
installation of package '/Users/isimee/Desktop/R_scripts/findalpha.R' had non-zero exit status
findalpha.R is one of the packages I am trying to install.
I am using terminal on a mac but have tried from R directly and it doesnt work. I have downloaded the devtools but doesnt work either apart from that I dont really know what to do with it.
Help would be very much appreciated. Thanks a lot.

Related

Problems when installing the broom package

I can not install the broom package. When I try I get this Error Message, that I can't understand:
installing source package 'broom' ...
** package 'broom' successfully unpacked and MD5 sums checked
** using staged installation
Warning in file(file, if (append) "a" else "w") :
cannot open file 'C:/Users/AndrisLagerlvf/Documents/R/win-library/3.6/00LOCK-broom/00new/broom/DESCRIPTION': No such file or directory
Error in file(file, if (append) "a" else "w") :
cannot open the connection
ERROR: installing package DESCRIPTION failed for package 'broom'
removing 'C:/Users/AndrésLagerlöf/Documents/R/win-library/3.6/broom'
Warning in install.packages :
installation of package ‘broom’ had non-zero exit status
I am using a Widows computer with Windows Version 1909 (OS-version 18363.657), and RStudio Version 1.2.5033, and R version 3.6.2.
When I update some packages it works fine, but when I try to update other packages I get similar error messages as above.
Further notes: I used to have the broom package installed, and tried to update the package but when I got the error message I uninstalled the package and then tried to install the package again, but got the same error message, so now I don't have access to the package.
Any suggestions on how to fix would be great! Thanks!
Check out/notice the difference between
C:/Users/AndrisLagerlvf/Documents/R/win-library/3.6
and
'C:/Users/AndrésLagerlöf/Documents/R/win-library/3.6/broom
That is (international) Encoding showing its ugly face.
I would suggest the following as a solution and also a quite common good practice.
Create a (most probably local) directory somewhere you have "good" access to that DOES NOT contain any exotic characters (eg C:\R-PKGS\win-library\3.6) then set this as your standard library path
.libPaths(c("C:/R-PKGS/win-library/3.6", .libPaths())) #watch out for the direction of the slashes (normal ones - not backslashes, since this is R code)
Put the above line into a/your ~/.Rprofile file eg via running file.edit('~/.Rprofile') in the Console.
Let me know if that does not help? I am curious because you mentioned that sometimes it works - my guess is that your routine works for those packages that are installed in R_HOME/library and not for those installed under your User directory, which contains the exotic characters. Additionally you could minggle around with your locale settings until R is satisfied with them, but I have not tested such a solution (yet) ... since this would involve heavy adjustments, to my locale and typeset settings (sorry for that).
Or even better if you want R to branch according to your Version ie if you have multiple subfolders for multiple differing minor R versions (eg R-3.5 and R-3.6 side by side) ie this is how my libPath setting looks like
.libPaths( c( paste0( "D:/R_LIB/", substr(getRversion(),1,3) ), .libPaths() ) )
This has the advantage compared to the ENV VAR approach that you can manage multiple R.version library subfolders ...

How to remove all packages in R

Yesterday I tried to open a R Markdown in Rstudio. Rstudio forced me to download something, Now everytime I restart Rstudio or install package, it shows
Error in loadNamespace(name) : there is no package called ‘yaml’
Error in loadNamespace(name) : there is no package called ‘yaml’"
I saw someone say that I can resolve this by removing all packages I have installed, but I only found the remove.package function, which can only remove one package at a time.
If I want to delete all packages, what should I do?
(I use Mac)

cannot install R package using install_local on linux server

I have been trying to install "ncdf4" package in R locally for more than two days now. First I tried installing "ncdf4" package with package.install() but it did not work. Afterwards, I downloaded binary file of the package and tried installing it using install_local:
> library("devtools")
> install_local("/path to the package/",quiet=FALSE)
However, this generated following error:
Installation failed: cannot open the connection
Warning message:
In read.dcf(path) :
cannot open compressed file
'/<path_to_the package>/DESCRIPTION', probable reason 'Not a directory'
I also could not install some other packages using install_local(). Can anyone help me out in troubleshooting this error?

Error installing packages in Rstudio

I have R 3.2.2 setup installed in my system,with RStudio version 0.99.489. When I tried to install rJava package,
install.packages("rJava")
I am getting following Error:
Warning in install.packages :
downloaded length 4878 != reported length 200
Error in install.packages : subscript out of bounds
But if I run the below command before installing any package,it works fine, but I don't want to do this every time I install a package.
options(repos=structure(c(CRAN="http://cran.us.r-project.org")))
You can stick the line you want executed at every startup in your .Rprofile file which should be in your home directory. I have 3.2.3 version of R and that worked; however I do get a warning message about using a non-http version of the site.
Similarly to you, I was finding the original repository the system was using was failing to install the packages--not finding the package or downloading a file with too few bytes, perhaps because of a transient problem. You might want to consider not putting this in your .Rprofile file or commenting the line outin case this is a temporary workaround.

ggplot2 version 1.0.1 won't load into R 3.2.2 for Windows

I just started using R and downloaded ggplot2
install.packages("ggplot2")
I get the following warning:
Warning in install.packages:
unable to move temporary installation '\\CHI-FIlE-01\UserFolders$\naresh.kavuri\Documents\R\win-library\3.2\file27ac2d3b613c\ggplot' to '\\CHI-FILE-01\UserFolders$\naresh.kavuri\Documents\R\win-library\3.2\ggplot2'
This warning is followed up with this error:
Error: invalid version specification 'NA'
In addition: warning message:
In utils:::packageDescription(packageName, fields = "Version") :
no package 'knitr' was found
As anyone come across this problem before? Did I do something wrong in the setup?
If you have multiple versions of R running, and you try to update or reinstall a package in one version of R while it is loaded in another, then the old version of the package doesn't get completely removed.
Try closing down all instances of R, manually deleting the folder containing the package, then opening a single version of R and reinstalling.
As Pascal commented, antivirus file scans can also interfere with the installation process. Sometimes downloading the package zip/tar.gz file then installing from disk can circumvent the issue.

Resources