Reputation: 6206
I use R on via the terminal on macOS Catalina. I had run into issues installing libraries, e.g.
> install.packages("caret")
Warning: unable to access index for repository http://cran.revolutionanalytics.com/src/contrib:
cannot open URL 'http://cran.revolutionanalytics.com/src/contrib/PACKAGES'
Warning: unable to access index for repository http://cran.revolutionanalytics.com/bin/macosx/el-capitan/contrib/3.6:
cannot open URL 'http://cran.revolutionanalytics.com/bin/macosx/el-capitan/contrib/3.6/PACKAGES'
Warning message:
package ‘caret’ is not available (for R version 3.6.0)
This issue can be solved by:
chooseCRANmirror(12)
I added that line to my ~/.Rprofile
so that it auto-loads it at the start of every session. However, that returns:
Error: could not find function "chooseCRANmirror" [Previously saved workspace restored]
, and doesn't load the R profile, even though it works when I put it directly into my console. Why is this? And is there a solution to auto chooseCRANmirror(12) without having to manually do it each session?
Here is the rest of my ~/.Rprofile
:
local({r <- getOption("repos")
r["CRAN"] <- "http://cran.revolutionanalytics.com"
options(repos=r)})
chooseCRANmirror(12)
options(stringsAsFactors=FALSE)
options(max.print=100)
options(scipen=10)
options(editor="vim")
# options(show.signif.stars=FALSE)
options(menu.graphics=FALSE)
options(prompt="> ")
options(continue="... ")
options(width = 80)
q <- function (save="no", ...) {
quit(save=save, ...)
}
utils::rc.settings(ipck=TRUE)
.First <- function(){
if(interactive()){
library(utils)
timestamp(,prefix=paste("##------ [",getwd(),"] ",sep=""))
}
}
.Last <- function(){
if(interactive()){
hist_file <- Sys.getenv("R_HISTFILE")
if(hist_file=="") hist_file <- "~/.RHistory"
savehistory(hist_file)
}
}
if(Sys.getenv("TERM") == "xterm-256color")
library("colorout")
sshhh <- function(a.package){
suppressWarnings(suppressPackageStartupMessages(
library(a.package, character.only=TRUE)))
}
auto.loads = c("viridis", "tidyverse", "data.table")
if(interactive()){
invisible(sapply(auto.loads, sshhh))
}
.env <- new.env()
attach(.env)
.env$unrowname <- function(x) {
rownames(x) <- NULL
x
}
.env$unfactor <- function(df){
id <- sapply(df, is.factor)
df[id] <- lapply(df[id], as.character)
df
}
Upvotes: 0
Views: 184
Reputation: 9107
You need to specify the package.
utils::chooseCRANmirror(12)
.Rprofile
only loads the base package. See ?Startup
.
Note that when the site and user profile files are sourced only the base package is loaded, so objects in other packages need to be referred to by e.g. utils::dump.frames or after explicitly loading the package concerned.
Upvotes: 2