Installing packages on R fails when loading .Rprofile

When I try to install packages in R, the installation almost always fails if my .Rprofile . However, when I load R with the --vanilla flag, I can install packages without problems. Here is the result of the R session with the problem. I think the difficulty is either with my .First() function in .Rprofile or with the history file. My rprofile file is here .

 $ install.packages("SuppDists") Installing package into '/home/lmullen/R/x86_64-pc-linux-gnu-library/3.0' (as 'lib' is unspecified) trying URL 'http://cran.cnr.Berkeley.edu/src/contrib/SuppDists_1.1-9.tar.gz' Content type 'application/x-gzip' length 140784 bytes (137 Kb) opened URL ================================================== downloaded 137 Kb Loading required package: stats Loading required package: sp rgeos version: 0.2-19, (SVN revision 394) GEOS runtime version: 3.3.3-CAPI-1.7.4 Polygon checking: TRUE rgdal: version: 0.8-10, (SVN revision 478) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 1.9.0, released 2011/12/29 Path to GDAL shared files: /usr/share/gdal/1.9 Loaded PROJ.4 runtime: Rel. 4.7.1, 23 September 2009, [PJ_VERSION: 470] Path to PROJ.4 shared files: (autodetected) Error in .External2(C_loadhistory, file) : no history mechanism available Calls: .First -> <Anonymous> Execution halted The downloaded source packages are in '/tmp/RtmpX42EEZ/downloaded_packages' Warning message: In install.packages("SuppDists") : installation of package 'SuppDists' had non-zero exit status 

Does anyone know what the problem is?

+4
source share
3 answers

I figured out the lines in my .Rprofile that were causing the problem, although I don't know why they are causing the problem. The functions of .First and .Last were as follows:

 .First <- function() { utils:::loadhistory(file = "~/.Rhistory") cat("\nSuccessfully loaded .Rprofile at", date(), "\n\n") } .Last <- function() { utils:::savehistory(file = "~/.Rhistory") } 

Commenting on the lines about saving and loading history, I can install packages.

0
source

Henrik gave me the answer on the R-devel mailing list:

Using

if (interactive()) utils::loadhistory(file = "~/.Rhistory")

should solve your problem. The reason is that install.packages() on turn starts a non-interactive child R process that installs the package. When this process loads your startup file, it fails because this function can only be used interactively.

0
source

In Ubunto:

I installed it from outside R and it worked well, thanks @ hugo-raguet:

 sudo apt-get -y install build-essential sudo apt-get -y install r-cran-igraph 

There is no need to set igraph later in R, I suppose.

0
source

Source: https://habr.com/ru/post/1497111/


All Articles