Skip to content

package_info() returns NA libpath for loaded package when its libpath is not in current .libPaths() #128

@slager

Description

@slager

Perhaps naively, I had expected package_info() to tell me where the package was loaded from even if not from any of my current .libPaths().

library(withr)
library(sessioninfo)
library(remotes)

mylib <- tempfile()
dir.create(mylib)

install_github('hadley/genzplyr', force = TRUE, lib = mylib)
#> Using github PAT from envvar GITHUB_PAT. Use `gitcreds::gitcreds_set()` and unset GITHUB_PAT in .Renviron (or elsewhere) if you want to use the more secure git credential store instead.
#> Downloading GitHub repo hadley/genzplyr@HEAD
#> 
#> ── R CMD build ─────────────────────────────────────────────────────────────────
#> * checking for file ‘/tmp/RtmpduYRXt/remotes873fd94ce2fc/hadley-genzplyr-df238ea/DESCRIPTION’ ... OK
#> * preparing ‘genzplyr’:
#> * checking DESCRIPTION meta-information ... OK
#> * checking for LF line-endings in source and make files and shell scripts
#> * checking for empty or unneeded directories
#> * building ‘genzplyr_0.0.0.9000.tar.gz’
library(genzplyr, lib.loc = mylib)
#> genzplyr loaded fr fr 💅
#> Your data wrangling is about to be bussin no cap

test_fn <- function(){
  package_info() |>
    yeet(package == 'genzplyr') |>
    main_character('library') |>
    as.character()
}

# library is NA when loaded path is not currently in .libPaths()
test_fn()
#> [1] NA

# library is resurrected
with_libpaths(mylib, test_fn())
#> [1] "/tmp/RtmpduYRXt/file873fd99593c6"

Created on 2025-12-11 with reprex v2.1.1

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