swang87 / fc

R package for function composition utilizing standard evaluation
0 stars 0 forks source link

Does not allow referencing of global variables. #17

Open swang87 opened 5 years ago

swang87 commented 5 years ago

See for example,

fc(sample, x = letters)
swang87 commented 5 years ago

Look into 'where()' function in pryr.

kaneplusplus commented 5 years ago

This is subtle. If I say:

x <- iris
fc(sample, x = head(x)

does this mean I want x to be the first 6 rows of iris or does it mean that I should take the first 6 elements of whatever is passed to the return function and sample from it? I think the answer is the latter. In this case, if we really want to sample from letters, like in the example you could say:

fc(sample, x = base::letters)

Here I'm explicitly referencing an object in it's environment.

It seems like we might want to roll this change back.

Thoughts?

kaneplusplus commented 5 years ago

Note that even this isn't sufficient since:

letters[1] <- "A"
letters[1]
base::letters[1]

We could extend the :: operator to look in the current environment.

swang87 commented 5 years ago

I agree with your first comment. It's an excellent point that I totally didn't see before. Not quite understanding what you mean by the letters[1] example. Are you saying that we might potentially want:

fc(sample, x = head(letters,3) , size=n)

where letters is given by:

letters <- base::letters
letters[1] <- "A"

we may have issues?

swang87 commented 5 years ago

Meeting 2/27: Include some extra info to tell fc() whether or not to bring in a global variable into the fc environment.

fc(sample, x = head(grab(iris)))