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

New renv 1.0.0 not working. Error in renv::renv_bootstrap_validate_version() #1625

Closed
MalteSteinDE opened this issue Aug 3, 2023 · 4 comments

Comments

@MalteSteinDE
Copy link

MalteSteinDE commented Aug 3, 2023

Non of my R projects is working with the new renv 1.0.0 version. Therefore I started a complete fresh project and called renv:init():

R version 4.2.3 (2023-03-15 ucrt) -- "Shortstop Beagle"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> renv::init()
The following package(s) will be updated in the lockfile:

# CRAN -------------------------------------------------------------------
- renv   [* -> 1.0.0]

The version of R recorded in the lockfile will be updated:
- R      [* -> 4.2.3]

- Lockfile written to 'Y:/Cytemation_Dev/R packages/test222/renv.lock'.

Restarting R session...

Error in description[["Version"]] : subscript out of bounds
In addition: Warning message:
In packageDescription("renv", lib.loc = dirname(path)) :
  no package 'renv' was found

The related function with the error is renv_bootstrap_validate_version (https://github.com/rstudio/renv/blob/1490ee1d41db6c2f38848ae18af5607a549bfdde/R/bootstrap.R)

function (version, description = NULL) 
{
  description <- description %||% {
    path <- getNamespaceInfo("renv", "path")
    packageDescription("renv", lib.loc = dirname(path))
  }
# ... more code

Testing just this code is causing the issue which is causing later the error of calling the description$Version.

> path <- getNamespaceInfo("renv", "path")
> path
[1] "Y:/Cytemation_Dev/R packages/test222/renv/library/R-4.2/x86_64-w64-mingw32/renv"
> packageDescription("renv", lib.loc = dirname(path))
[1] NA
Warning message:
In packageDescription("renv", lib.loc = dirname(path)) :
  no package 'renv' was found

Call packageDescription just with the package name is working in giving me the correct path in the renv project library:

> packageDescription("renv")
Package: renv
Type: Package
Title: Project Environments
Version: 1.0.0
### delete some records
Packaged: 2023-07-07 21:11:12 UTC; kevin
Repository: CRAN
Date/Publication: 2023-07-07 21:50:02 UTC
Built: R 4.2.3; ; 2023-07-26 00:34:25 UTC; windows

-- File: Y:/Cytemation_Dev/R packages/test222/renv/library/R-4.2/x86_64-w64-mingw32/renv/Meta/package.rds 

The package is correctly installed in the project library, but cannot be found with the lib.loc statement in packageDescription function.
Same issue will show up for any installed package in the project library.

FYI: I don't have this issue on my Posit Workbech running on linux server.
R version 4.2.3 (2023-03-15) -- "Shortstop Beagle" and Platform: x86_64-pc-linux-gnu (64-bit)

@kevinushey
Copy link
Collaborator

That is pretty surprising to me. Is there anything unique about the Y:/ drive? Is it a network filesystem or something similar?

It might be helpful if you could debug(packageDescription) to isolate where exactly the failure is occurring.

@MalteSteinDE
Copy link
Author

MalteSteinDE commented Aug 9, 2023

The Y drive is a dual protocol drive (SMB+NFS), and security is controlled in Unix style.

Debug was not so helpful:

> debug(packageDescription)
> path <- getNamespaceInfo("renv", "path")
> path
[1] "Y:/Cytemation_Dev/R packages/test222/renv/library/R-4.2/x86_64-w64-mingw32/renv"
> packageDescription("renv", lib.loc = dirname(path))
debugging in: packageDescription("renv", lib.loc = dirname(path))
debug: {
    retval <- list()
    if (!is.null(fields)) {
        fields <- as.character(fields)
        retval[fields] <- NA
    }
    pkgpath <- if (is.null(lib.loc)) {
        if (pkg == "base") 
            file.path(.Library, "base")
        else if (isNamespaceLoaded(pkg)) 
            getNamespaceInfo(pkg, "path")
        else if ((envname <- paste0("package:", pkg)) %in% search()) {
            attr(as.environment(envname), "path")
        }
    }
    if (is.null(pkgpath)) 
        pkgpath <- ""
    if (pkgpath == "") {
        libs <- if (is.null(lib.loc)) 
            .libPaths()
        else lib.loc
        for (lib in libs) if (file.access(file.path(lib, pkg), 
            5) == 0L) {
            pkgpath <- file.path(lib, pkg)
            break
        }
    }
    if (pkgpath == "") {
        warning(gettextf("no package '%s' was found", pkg), domain = NA)
        return(NA)
    }
    if (file.exists(file <- file.path(pkgpath, "Meta", "package.rds"))) {
        desc <- readRDS(file)$DESCRIPTION
        if (length(desc) < 1) 
            stop(gettextf("metadata of package '%s' is corrupt", 
                pkg), domain = NA)
        desc <- as.list(desc)
    }
    else if (file.exists(file <- file.path(pkgpath, "DESCRIPTION"))) {
        dcf <- read.dcf(file = file)
        if (NROW(dcf) < 1L) 
            stop(gettextf("DESCRIPTION file of package '%s' is corrupt", 
                pkg), domain = NA)
        desc <- as.list(dcf[1, ])
    }
    else file <- ""
    if (nzchar(file)) {
        enc <- desc[["Encoding"]]
        if (!is.null(enc) && !is.na(encoding)) {
            if (missing(encoding) && Sys.getlocale("LC_CTYPE") == 
                "C") 
                encoding <- "ASCII//TRANSLIT"
            if (encoding != enc) {
                newdesc <- try(lapply(desc, iconv, from = enc, 
                  to = encoding))
                dOk <- function(nd) !inherits(nd, "try-error") && 
                  !anyNA(nd)
                ok <- dOk(newdesc)
                if (!ok && !endsWith(encoding, "//TRANSLIT")) 
                  ok <- dOk(newdesc <- try(lapply(desc, iconv, 
                    from = enc, to = paste0(encoding, "//TRANSLIT"))))
                if (!ok) 
                  ok <- dOk(newdesc <- try(lapply(desc, iconv, 
                    from = enc, to = "ASCII//TRANSLIT", sub = "?")))
                if (ok) 
                  desc <- newdesc
                else warning("'DESCRIPTION' file has an 'Encoding' field and re-encoding is not possible", 
                  call. = FALSE)
            }
        }
        if (!is.null(fields)) {
            ok <- names(desc) %in% fields
            retval[names(desc)[ok]] <- desc[ok]
        }
        else retval[names(desc)] <- desc
    }
    if ((file == "") || (length(retval) == 0)) {
        warning(gettextf("DESCRIPTION file of package '%s' is missing or broken", 
            pkg), domain = NA)
        return(NA)
    }
    if (drop && length(fields) == 1L) 
        return(retval[[1L]])
    class(retval) <- "packageDescription"
    if (!is.null(fields)) 
        attr(retval, "fields") <- fields
    attr(retval, "file") <- file
    retval
}
Browse[2]> c
exiting from: packageDescription("renv", lib.loc = dirname(path))
[1] NA
Warning message:
In packageDescription("renv", lib.loc = dirname(path)) :
  no package 'renv' was found

But I searched for the difference in this code on different drives and the file.access is the issue.
Is giving as result -1 and therefore the pkgpath will be "" and the package will not be found.

> file.access(file.path(lib, pkg), 5)
Y:/Cytemation_Dev/R packages/test222/renv/library/R-4.2/x86_64-w64-mingw32/renv 
                                                                             -1 

> file.info(file.path(lib, pkg))
                                                                                size isdir mode
Y:/Cytemation_Dev/R packages/test222/renv/library/R-4.2/x86_64-w64-mingw32/renv    0  TRUE  777
                                                                                              mtime
Y:/Cytemation_Dev/R packages/test222/renv/library/R-4.2/x86_64-w64-mingw32/renv 2023-08-03 09:04:23
                                                                                              ctime
Y:/Cytemation_Dev/R packages/test222/renv/library/R-4.2/x86_64-w64-mingw32/renv 2023-08-03 10:23:43
                                                                                              atime exe
Y:/Cytemation_Dev/R packages/test222/renv/library/R-4.2/x86_64-w64-mingw32/renv 2023-08-03 10:23:43  no

Same test on Y is working on Linux Posit workbench.

@kevinushey
Copy link
Collaborator

Thanks! I believe 138325f should resolve the issue, but the fact that R's file.access() doesn't work as you expect for this folder could be problematic in other scenarios.

@MalteSteinDE
Copy link
Author

Thanks for solving this issue. We don't have issue with renv::init() anymore. But yes, file.access() is causing another issue with renv.

I posted it in an new issue:
#2058

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