Skip to content

Does re-use-ing a module require an explicit detach? #24

@barryrowlingson

Description

@barryrowlingson

If I use a module file with attach=TRUE, then changes in the module file don't get reflected if I re-run use. Example:

No foo function:

> foo(3)
Error in foo(3) : could not find function "foo"

This file defines one function:

> system("cat mod.Rmod")
foo <- function(x) {
    sqrt(x)
}

Use it and try it:

> use("mod.Rmod",attach=TRUE)
> foo(3)
[1] 1.732051

Now edit the file to return x squared, use it again and get an update message:

> system("cat mod.Rmod")
foo <- function(x) {
    x*x
}
> use("mod.Rmod",attach=TRUE)
Replacing attached import/use on search path for: modules:mod.Rmod.

but foo still does square-root:

> foo(3)
[1] 1.732051

detach and re-use and I get the new behaviour:

> detach(2)
> foo
Error: object 'foo' not found
> use("mod.Rmod",attach=TRUE)
> foo(3)
[1] 9
> 

Is this expected or documented? Using reInit=TRUE doesn't change the above either.

I'm currently using R 3.6.3 and modules: 0.8.0

Thanks

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions