Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error about "file exists" when opening a project #609

Open
bioteamMichael opened this issue Jul 9, 2020 · 2 comments
Open

Error about "file exists" when opening a project #609

bioteamMichael opened this issue Jul 9, 2020 · 2 comments

Comments

@bioteamMichael
Copy link

I just updated R via homebrew, and now when I launch the RStudio IDE on my mac and open an existing project I get

Warning message:
In file.symlink(from, to) :
  cannot symlink '/usr/local/Cellar/r/4.0.2_1/lib/R/library/base' to '/Users/mike/src/work/gRED/packrat/lib-R/x86_64-apple-darwin19.5.0/4.0.2/base', reason 'File exists'

I'm assuming that this is something with the update to R, since the symlink exists but points to the old version of R I had:

$ ls -l /Users/mike/src/work/gRED/packrat/lib-R/x86_64-apple-darwin19.5.0/4.0.2/base
lrwxr-xr-x 1 mike staff 44 Jun 23 21:58 /Users/mike/src/work/gRED/packrat/lib-R/x86_64-apple-darwin19.5.0/4.0.2/base -> /usr/local/Cellar/r/4.0.2/lib/R/library/base

Running packrat::restore() didn't seem to help out any.

@bioteamMichael
Copy link
Author

Quitting RStudio, deleting all the symlinks in ~/src/work/gRED/packrat/lib-R/x86_64-apple-darwin19.5.0/4.0.2, and then relaunching caused everything to be relinked correctly, but I'd be curious to know why that happened.

Could it be because homebrew provided an updated build of 4.0.2?

@kevinushey
Copy link
Contributor

That seems possible. Packrat is supposed to be able to refresh those symlinks on demand as required.

symlinkSystemPackages <- function(project = NULL) {
project <- getProjectDir(project)
# skip symlinking if requested by user
if (identical(opts$symlink.system.packages(), FALSE))
return(FALSE)
# Get the path to the base R library installation
sysLibPath <- normalizePath(R.home("library"), winslash = "/", mustWork = TRUE)
## Get the system packages
sysPkgs <- utils::installed.packages(sysLibPath)
sysPkgsBase <- sysPkgs[!is.na(sysPkgs[, "Priority"]), ]
sysPkgNames <- rownames(sysPkgsBase)
## Make a directory where we can symlink these libraries
libRdir <- libRdir(project = project)
if (!file.exists(libRdir))
if (!dir.create(libRdir, recursive = TRUE))
return(FALSE)
## Generate symlinks for each package
for (pkg in sysPkgNames) {
source <- file.path(sysLibPath, pkg)
target <- file.path(libRdir, pkg)
if (!ensurePackageSymlink(source, target))
return(FALSE)
}
TRUE
}

ensurePackageSymlink <- function(source, target) {
cleanRecursivePackageSymlinks(source)
# If we have a symlink already active in the
# target location, check that it points to the
# library corresponding to the current running
# R session.
if (file.exists(target)) {
if (isPathToSamePackage(source, target))
return(TRUE)
# Remove the old symlink target (swallowing errors)
tryCatch(
unlink(target, recursive = !is.symlink(target)),
error = identity
)
# Check if the file still exists and warn if so
if (file.exists(target)) {
# request information on the existing file
info <- paste(capture.output(print(file.info(target))), collapse = "\n")
msg <- c(
sprintf("Packrat failed to remove a pre-existing file at '%s'.", target),
"Please report this issue at 'https://github.com/rstudio/packrat/issues'.",
"File info:",
info
)
warning(paste(msg, collapse = "\n"))
}
}
# If, for some reason, the target directory
# still exists, bail as otherwise symlinking
# will not work as desired.
if (file.exists(target))
stop("Target '", target, "' already exists and is not a symlink")
# Perform the symlink.
symlink(source, target)
# Success if the file now exists
file.exists(file.path(target, "DESCRIPTION"))
}

Regardless, the right way to "fix" this is to delete the old symlinks so that Packrat can refresh them, or to simply disable sandboxing altogether (if you don't need to rely on the system library being sandboxed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants