Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion R/loadfast.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ load_fast <- function(path = ".", helpers = TRUE, attach_testthat = NULL, full =
desc_path <- file.path(abs_path, "DESCRIPTION")
if (!file.exists(desc_path)) stop("DESCRIPTION file not found at: ", desc_path)
desc_fields <- read.dcf(desc_path)
pkg_name <- if ("Package" %in% colnames(desc_fields)) trimws(desc_fields[1L, "Package"]) else ""
pkg_name <- if ("Package" %in% colnames(desc_fields)) unname(trimws(desc_fields[1L, "Package"])) else ""
if (!nzchar(pkg_name)) stop("No valid 'Package' field found in DESCRIPTION")

pkg_env_name <- paste0("package:", pkg_name)
Expand Down Expand Up @@ -257,6 +257,9 @@ load_fast <- function(path = ".", helpers = TRUE, attach_testthat = NULL, full =
ns_env[[".__NAMESPACE__."]] <- info
info[["spec"]] <- c(name = pkg_name, version = "0.0.0")
setNamespaceInfo(ns_env, "exports", new.env(hash = TRUE, parent = baseenv()))
dimpenv <- new.env(parent = baseenv(), hash = TRUE)
attr(dimpenv, "name") <- paste0("lazydata:", pkg_name)
setNamespaceInfo(ns_env, "lazydata", dimpenv)
setNamespaceInfo(ns_env, "imports", list(base = TRUE))
setNamespaceInfo(ns_env, "path", abs_path)
setNamespaceInfo(ns_env, "dynlibs", NULL)
Expand Down
24 changes: 24 additions & 0 deletions test_loadfast.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ check("isNamespace() returns TRUE", quote(
isNamespace(ns)
))

check("lazydata env exists in namespace info", quote(
is.environment(ns[[".__NAMESPACE__."]][["lazydata"]])
))

check("lazydata env is named correctly", quote(
attr(ns[[".__NAMESPACE__."]][["lazydata"]], "name") == "lazydata:devpackage"
))

# --- Search path ---
check("package:devpackage is on the search path", quote(
"package:devpackage" %in% search()
Expand Down Expand Up @@ -1153,6 +1161,22 @@ check("same-name: second path is now the active namespace path", quote(
)
))

# --------------------------------------------------------------------------
# 3f2: base::attachNamespace compatibility
# --------------------------------------------------------------------------
cat("\n--- 3f2: base::attachNamespace compatibility ---\n\n")

tmp_attach <- tempfile("loadfast_attach_")
copy_baseline(tmp_attach)
rename_package(tmp_attach, "pkgattach")
ns_attach <- load_fast(tmp_attach, helpers = FALSE, attach_testthat = FALSE)

check("base::attachNamespace does not fail due to missing lazydata env", quote({
detach("package:pkgattach", unload = FALSE)
base::attachNamespace(ns_attach)
"package:pkgattach" %in% search()
}))

# --------------------------------------------------------------------------
# 3g: Same-name different-path cache flip-flop and renv.lock path scoping
# --------------------------------------------------------------------------
Expand Down
Loading