Possibility of using multiple CRAN mirrors? [RStudio] - r

I've spent the last 4 hours trying to find out why I wasn't able to install any packages in R (it started with me trying to install a package I was developing). It would just stall for +5 minutes without doing anything or outputting anything to the terminal. I tracked the issue down to the following call:
repos <- structure("https://cran.rstudio.com/", .Names = "CRAN")
type <- "both"
utils::available.packages(utils::contrib.url(repos, type), type = type)
I realized after a while that it was just the RStudio CRAN mirror, and when I changed the repo to "https://cran.case.edu/", it started working. However, there was literally no indication of this on the surface--and it took forever for me to find out what the problem was.
My question is this: Is there a way of using multiple CRAN repos so when one fails, others are used? Or at least a way that will prevent this from happening again?

Related

R devtools: use local dependencies

This bounty has ended. Answers to this question are eligible for a +100 reputation bounty. Bounty grace period ends in 4 hours.
antonio wants to draw more attention to this question:
Explain what is the proper workflow when you are building two packages, where one depends on the other. What is the correct way to run devtools::check() on the depending-on package?
I want to add a local package dependency using R devtools.
The suggested way to add packages to the package DESCRIPTION file is one of the two functions use_package() and use_dev_package(), from the usethis package. The latter adds a dependency on an in-development package. The function help shows the following prototype:
use_dev_package(package, type = "Imports", remote = NULL)
where remote is
a character string to specify the remote, e.g. ‘"gitlab::jimhester/covr"’, using any syntax supported by the remotes package.
The remotes vignette shows the following
# Local
Remotes: local::/pkgs/testthat
So the command should be along these lines:
use_dev_package(foopack, type = "Imports", remote = "local::<foopack>")
However, what should be the path to the foopack. An absolute one or relative to project dir? The root package directory or the R directory with the code, or perhaps the foopack.tar.gz build?
All attempts failed for me.
Needless to say that, beyond having the local dependency properly listed in the DESCRIPTION file, I need it to be seen by the devtools build & check functions.
Edit
As regards use_dev_package(), I found a solution:
if I use devtools::check(), then the dependency appears in the search path, and use_dev_package() does not complain any more (see answer below).
However, it is still unclear to me what arguments should I use to make a development check() for the main package, in particular when the package has a vignette.
Ideally, I should be able to pass the check with local dependencies by passing cran = FALSE, but this still gives
"Package required but not available".
It seems that I have to check the local dependencies before adding them to the description file.
devtools::check("path/to/foopack")
usethis::use_dev_package("foopack", remote ="local::path/to/foopack")
The paths can be relative or absolute, and even a single colon works.
It might be worth noting that, when I build the main package, I can use the ordinary:
devtools::build()
but, for a successful check, I need to use the remote argument:
devtools::check(remote = TRUE)
I can't see a rationale for restating what is in the DESCRIPTION file, but I do not have enough expertise to say it's a bug.
Let's see what the others say in this regard.
Edit
Unfortunately, it seems that the remote argument above does not apply to vignettes. So, if I add a vignette to the package, checks fail with local packages
Until an actual solution is found, all I can do is (sadly) to ignore vignette checks:
devtools::check(remote = TRUE, vignettes = FALSE)

devtools::check generates an error (install options '--no-html --no-multiarch) at seemingly randomly times

I am creating my own package and use devtools to document and check the package. About 50% of the time that I run devtools::check() it ends with this error:
❯ checking whether package 'snafun' can be installed ... ERROR See below...
── Install failure ─────────────────────────────────────────────────────────────────────────────────────────────────
install options '--no-html --no-multiarch
However, this only happens about half the time. Sometimes it doesn't and sometimes it does. I can run devtools::check several times in a row (without making any change to the code or the session in between) and get this error on half of the runs, and on the other half not. And sometimes it seems to help if I restart the session in between an other times it makes no difference.
I have tried playing with the arguments of devtools::check, but that doesn;t seem to affect the error (which could be related to this being an "Install failure" and devtools::check doesn't have install arguments).
I am puzzled. I have the following questions:
what does this error even mean? Is it problematic?
what can make it occur and disappear seemingly randomly?
what might be a direction to solve this?
ps the package is quite large, so I can't really turn this into a reprex
I got exactly the same problem and I solved it installing the rcmdcheck package.
install.packages("rcmdcheck")
library(rcmdcheck)
rcmdcheck('MyPath/MyPackage')

Warning: unable to access index for repository https://www.stats.ox.ac.uk/pub/RWin/src/contrib: [duplicate]

This question already has answers here:
Problems with installation R packages
(3 answers)
Closed 5 years ago.
From today, every time I try to install a new package on R (3.4.1) with Rstudio 1.0.143 I receive this error message:
Warning: unable to access index for repository https://www.stats.ox.ac.uk/pub/RWin/src/contrib:
cannot open URL 'https://www.stats.ox.ac.uk/pub/RWin/src/contrib/PACKAGES'
I change the CRAN mirror in Global options>packages but it still shows this error. The packages have started downloading from a different server than stats.ox.ac.uk but there is huge delay while R tries to connect to stats.ox.ac.uk. Is this a global problem, or just happening to me? If global, is there a workaround to stop this serror message from showing?
Thanks.
Deep
(Dwaipayan Adhya)
I'm guessing this is a temporary issue (but an annoying one nonetheless and one that I dealt with this morning). That repository is most likely an additional one set alongside the "CRAN" repository as "CRANextra". The solution is to redefine the repos option to not include CRANextra. You can use the setRepositories() command and unselect "CRANextra". Alternatively you could just run the following code which will remove all repositories except the "CRAN" selection.
options(repos = getOption("repos")["CRAN"])

Why am I getting a KeyError message?

Every time I call Pkg.Update() I get the following message:
KeyError: key "RDataSets" not found
I am aware that the correct name of the package is RDatasets and not RDataSets. When I first tried to install this package I must have made a mistake and entered a capital "S." Actually the package initially did not install and I had to painfully call Pkg.clone() for several packages it depended on.
Is this an indication of a serious problem? Everything seems to be working fine, but I am just starting (again) with Julia, so I am not sure. Also, can this problem be fixed?

Unexpected behavior of R after install on another EC2 instance

I'm fighting this problem second day straight with a completely sleepless night and I'm really starting to lose my patience and strength. It all started after I decided to provision another (paid) AWS EC2 instance in order to test my R code for dissertation data analysis. Previously I was using a single free tier t1.micro instance, which is painfully slow, especially when testing/running particular code. Time is much more valuable than reasonable number of cents per hour that Amazon is charging.
Therefore, I provisioned a m3.large instance, which I hope should have enough power to crunch my data comfortably fast. After EC2-specific setup, which included selecting Ubuntu 14.04 LTS as an operating system and some security setup, I installed R and RStudio Server per instructions via sudo apt-get install r-base r-base-dev as ubuntu user. I also created ruser as a special user for running R sessions. Basically, the same procedure as on the smaller instance.
Current situation is that any command that I issuing in R session command line result in messages like this: Error: could not find function "sessionInfo". The only function that works is q(). I suspect here a permissions problem, however, I'm not sure how to approach investigating permission-related problems in R environment. I'm also curious what could be the reasons for such situation, considering that I was following recommendations from R Project and RStudio sources.
I was able to pinpoint the place that I think caused all that horror - it was just a small configuration file "/etc/R/Rprofile.site", which I have previously updated with directives borrowed from R experts' posts here on StackOverflow. After removing questionable contents, I was able to run R commands successfully. Out of curiosity and for sharing this hard-earned knowledge, here's the removed contents:
local({
# add DISS_FLOSS_PKGS to the default packages, set a CRAN mirror
DISS_FLOSS_PKGS <- c("RCurl", "digest", "jsonlite",
"stringr", "XML", "plyr")
#old <- getOption("defaultPackages")
r <- getOption("repos")
r["CRAN"] <- "http://cran.us.r-project.org"
#options(defaultPackages = c(old, DISS_FLOSS_PKGS), repos = r)
options(defaultPackages = DISS_FLOSS_PKGS, repos = r)
#lapply(list(DISS_FLOSS_PKGS), function() library)
library(RCurl)
library(digest)
library(jsonlite)
library(stringr)
library(XML)
library(plyr)
})
Any comments on this will be appreciated!

Resources