From 03bfb2662bf71964d082ff89d9bfbf4561a2cf78 Mon Sep 17 00:00:00 2001 From: Justin Landis Date: Wed, 25 Jan 2023 14:57:36 -0500 Subject: [PATCH 1/2] small edits to handle #307 - modules become searchable after packages --- R/info.r | 23 ++++++++++++++++++++--- R/use.r | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/R/info.r b/R/info.r index 93c76ced..c7318be6 100644 --- a/R/info.r +++ b/R/info.r @@ -54,7 +54,7 @@ find_mod = function (spec, caller) { } `find_mod.box$pkg_spec` = function (spec, caller) { - pkg_info(spec) + if (pkg_exists(spec$name)) pkg_info(spec) else find_global_mod(spec, caller) } find_local_mod = function (spec, caller) { @@ -66,6 +66,17 @@ find_global_mod = function (spec, caller) { find_in_path(spec, mod_search_path(caller)) } +pkg_exists = function(name) { + out = logical(length(name)) + lib.loc = .libPaths() + for (i in seq_along(name)) { + pkg = name[i] + paths = file.path(lib.loc, pkg) + out[i] = any(file.exists(file.path(paths, "DESCRIPTION"))) + } + out +} + #' Find a module’s source location #' #' @param spec a \code{mod_spec}. @@ -100,7 +111,13 @@ find_in_path = function (spec, base_paths) { mod_file_candidates = function (spec, base_paths) { mod_path_prefix = merge_path(spec$prefix) ext = c('.r', '.R') - simple_mod = file.path(mod_path_prefix, paste0(spec$name, ext)) - nested_mod = file.path(mod_path_prefix, spec$name, paste0('__init__', ext)) + simple_mod = file_path(mod_path_prefix, paste0(spec$name, ext)) + nested_mod = file_path(mod_path_prefix, spec$name, paste0('__init__', ext)) map(file.path, base_paths, list(c(simple_mod, nested_mod))) } + +file_path = function(..., fsep = .Platform$file.sep) { + lst = list(...) + lst <- lst[vapply(lst, length, integer(1))>0] + .Internal(file.path(lst, fsep)) +} diff --git a/R/use.r b/R/use.r index 4bb0dce9..e8a77a15 100644 --- a/R/use.r +++ b/R/use.r @@ -294,6 +294,7 @@ use_one = function (declaration, alias, caller, use_call) { if (identical(declaration, quote(expr =)) && identical(alias, '')) return() rethrow_on_error({ + browser() spec = parse_spec(declaration, alias) info = find_mod(spec, caller) load_and_register(spec, info, caller) From 857ad8ff567f38d9a3db957245b36d3afb384591 Mon Sep 17 00:00:00 2001 From: Justin Landis Date: Wed, 25 Jan 2023 14:59:58 -0500 Subject: [PATCH 2/2] removing browser from testing --- R/use.r | 1 - 1 file changed, 1 deletion(-) diff --git a/R/use.r b/R/use.r index e8a77a15..4bb0dce9 100644 --- a/R/use.r +++ b/R/use.r @@ -294,7 +294,6 @@ use_one = function (declaration, alias, caller, use_call) { if (identical(declaration, quote(expr =)) && identical(alias, '')) return() rethrow_on_error({ - browser() spec = parse_spec(declaration, alias) info = find_mod(spec, caller) load_and_register(spec, info, caller)