Skip to content

.libPaths() after activation of a rv environment shows global library path. #400

@gwangjinkim

Description

@gwangjinkim

I am in a MacOS M3Max pro.

After installation of rv and generation of an environment

rv init test-rv
cd test-rv

rv activate
rv add tidyverse

R

I see:

.libPaths()
[1] "/Users/me/projects/R/test-rv/rv/library/4.4/arm64"                               <= projects' local library folder
[2] "/opt/homebrew/Caskroom/miniconda/base/envs/R443/lib/R/library"  <= global R's library folder

That means this repository uses primarily the rv environments' locally installed packages.
But if a package is not there but peresent int he global library folder which belongs to the global R outside of the rv environment,
a package would be recognized and imported from there.

Why is this bad? It means the session "sees" packages which are NOT recorded in the .lock file.
This violates the reproducibility of a project/session because packages other than in the current .lock file listed
can potentially be loaded.

I tried to get solely the rv environment's R packages in the project, one has to do at the beginning of the session:

.libPaths(.libPaths()[2], include.site=FALSE)

But this did not get rid of the global library path.

.libPath

function (new, include.site = TRUE) 
{
    if (!missing(new)) {
        new <- Sys.glob(path.expand(new))
        paths <- c(new, if (include.site) .Library.site, .Library)   # <- This line adds at the end of the paths vector `.Library`, the global library path.
        paths <- paths[dir.exists(paths)]
        .lib.loc <<- unique(normalizePath(paths, "/"))   # it somehow access it using a closure
    }
    else .lib.loc
}
<bytecode: 0x1503730c0>
<environment: 0x150374390>

Since .lib.loc is acceessed as a closure <<-, it seems to be we can't access it and delete .Library.

Is this desired that the global .Library path stays in .libPaths() ?
Shouldn't the environment have only the environment library accessible during the session?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions