wakefield icon indicating copy to clipboard operation
wakefield copied to clipboard

use package without calling library(wakefield)

Open jackwasey opened this issue 9 years ago • 4 comments

Thanks for making this useful package.

I tried to use it initially by doing:

wakefield::r_data_frame(id, age, n = 500)

This fails because, it seems, the id and age, etc, functions need to be available. It is beyond my knowledge, but perhaps you could interpret the symbols given in the wakefield namespace. Adding all those generic-sounding names to my namespace is a little worrying. I suppose I can call each function directly, using wakefield:: but this becomes more cumbersome. Just a thought.

jackwasey avatar Oct 04 '16 18:10 jackwasey

+1 to be able to use this without the package being loaded. e.g.

wakefield::r_data_theme(n = 100)

doesn't work without the package being loaded.

Would be great if this could work.

dannyparsons avatar Nov 01 '18 12:11 dannyparsons

@jackwasey This is a very generalizable problem. Nowadays many people prefer not to risk polluting their global search path.

  • One of the solutions could be manipulating enclosing chain of environments of the r_data_frame function, injecting bindings from the package's namespace such as id and age in a parent environment.
  • The other is to modify the r_data_frame function itself so that it always evaluate the symbols in the package's own namespace.

iqis avatar Aug 22 '19 03:08 iqis

@iqis any interest in a pull request?

trinker avatar Aug 22 '19 10:08 trinker

@trinker

I'm actually not able to reproduce the issue with wakefield::r_data_frame(id, age, n = 500)(which works perfectly) in R 3.6.0 and wakefield 0.3.3... Perhaps this has to do with R enforcing the use of namespaces in packages at some point between this question and now.

A packages function always look for bindings in the package's namespace first, it seems.

iqis avatar Aug 23 '19 16:08 iqis