1

I'm working in a package (and I'll include more later), and I'm doing a lot of changes and using it, and I'm looking for a method to can load the library without compile it, the lib is written in R.

I think the next structure:

Code
 libs/
  test_pkg1/
  test_pkg2/
 more code.R

Where the test_pkg are the dirs with the packages, they are already in the pkg format for R, the wd is set inside "Code", and then add "libs" to the library path in R, but R does not detect it.

I'm trying to use the libs in this both ways:

test_pkg1::func()
test_pkg2::func()
library(test_pkg1)
library(test_pkg2)

for the library, I can use devtools::load_all(path), and works great, but I don't want to mix the env with other funcs, so I need the other way too.

I'm not trying to use both at the same time, but I need both, the most important for this is the :: method.

I tested the libPath from here: Change R default library path using .libPaths in Rprofile.site fails to work

But I can't do it works...., using that I get the next result:

.libPaths( c( .libPaths(), "./libs") )
test_pkg1::func()
Error in namespaceExport(ns, exports) : undefined exports: func()
Although: Warning message:
In loadNamespace(name) : package ‘test_pkg1’ has no 'package.rds' in Meta/

Note, If I install the package, all works fine, the NAMESPACE file, contains the export functions, in any case, any error there and I should not be able to install and use the libs.

Thx.

Tests from comments:

Try library(pkg, lib.loc)

library("test_pkg1", lib.loc="./libs", verbose=TRUE)
Error in library("test_pkg1", lib.loc = "./libs", verbose = TRUE) : 
  ‘test_pkg1’ is not a valid installed package

Notice, the message is not, there is no package called, the package is detected, but seems, how is not built, I can't load it from library. I try build the package, but don't works either.

Try devtools::dev_mode(on = NULL, path = "libs")

Sadly, this method seems to have the same behavior as the .libsPath method.

Abs_0_
  • 55
  • 6
  • Are you trying to load and use a dev version and an installed version of the same package at the same time? You did a good job with detail and example code here, but I think some clarifications are still needed. The `library()` function in itself does has a `lib.loc` argument that you can use to direct the load to another path. –  Jan 19 '22 at 13:35
  • `devtools::load_all()` *does* allow you to use the `test_pkg1::func()` form as well. But ‘devtools’ isn’t supposed to be used for regular code, only during package *development*. Based on your project structure, R packages aren’t a good fit for you. You might want to check out [‘box’](https://klmr.me/box/), which allows you to have nested modules. This mirrors your current project structure, which R packages don’t allow. In fact, ‘box’ was developed specifically to address these shortcomings. – Konrad Rudolph Jan 19 '22 at 13:54
  • :O Box seems great, I'm checking it, I don't want to use this for normal code, is all for dev code, but have several packages, and test them, is pretty hard when for every change, you need to install all again.... that is why I'm looking into this methods. – Abs_0_ Jan 19 '22 at 14:13
  • Is `devtools::dev_mode()` of interest for this then? –  Jan 19 '22 at 14:15
  • Checked, sadly, no change, I get the same problems, was like.., just add the libs path to the R... – Abs_0_ Jan 19 '22 at 14:46

0 Answers0