Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R CMD check and no visible binding for global variable '.' #29

Open
gaborcsardi opened this issue Aug 5, 2014 · 11 comments
Open

R CMD check and no visible binding for global variable '.' #29

gaborcsardi opened this issue Aug 5, 2014 · 11 comments

Comments

@gaborcsardi
Copy link
Member

This is more of a question than an issue. You are probably aware of R CMD check complaining about the dot. I could just ignore the complaints of course, but they sometimes signal real errors, so every time I see the NOTE in the output, I need to check.

I just put this in the package:

. <- "Shut up"

Do you see any potential problems with this? It seems to me that it will not interfere with the pipes, but I don't know much about magrittr internals.

@smbache
Copy link
Member

smbache commented Aug 5, 2014

This is fine; but still I get annoyed somtimes..

I just toyed around with something; but it may be too weird. Essentially, I tried bundling the code in this gist (https://gist.github.com/smbache/a528d77f136a4bbf0c19) in a package to see if the compiler would complain. It didn't; and one of the functions will work at runtime (test), the other won't (test2). What I like about it is that you get explicit declaration of a variable which is only intended for nonstandard use; if it used in any standard way, an informative error is thrown. So test is an example of how to use it, and test2 shows the error in action. But maybe the syntax is too weird.
Also, I am not sure where the declare function should go as magrittr is not the only package which allows for some cool nonstandard stuff !

@gaborcsardi
Copy link
Member Author

Cool. declare is fine in magrittr, I guess, people can copy it if they want to. What I am not sure about, however, where the magrittr::declare( . <- as_nonstandard()) should go. It would need to go in each package that uses magrittr, as I see. Or people would need to import the dot. (But FIXME.)

Btw, did you try this with R CMD check? If it happens that it evaluates the promise, then our discussion is pretty academic....

@smbache
Copy link
Member

smbache commented Aug 5, 2014

R CMD is fine with it; I'm not convinced yet that I am ;-)

The <- tricks the check, but is never carried out. Rather delayedAssign does the assignment...

@jennybc
Copy link
Member

jennybc commented Feb 13, 2015

Is this entirely a joke?

. <- "Shut up"

I'd really like to make the NOTEs go away….

@gaborcsardi
Copy link
Member Author

@jennybc

Then just put this in the package and the NOTE goes away. You can change the exact text according to your mood. :)

@hadley
Copy link
Member

hadley commented Feb 13, 2015

Or do the official globalVariables(".")

@gaborcsardi
Copy link
Member Author

That just seems more cumbersome: :)

if(getRversion() >= "2.15.1")  utils::globalVariables(c("."))

More seriously, it is indeed better, it just instructs the check tool to ignore the dot, instead of actually creating a global variable.

@jennybc
Copy link
Member

jennybc commented Feb 13, 2015

The more you know! Thanks.

jennybc pushed a commit to jennybc/googlesheets that referenced this issue Feb 14, 2015
@smbache
Copy link
Member

smbache commented Feb 16, 2015

Wondering if the globalVariables should be the "offcial" (e.g. vignette/manual) suggested approach? Another option would be to wrap it in a more expressive magrittr function, which could be called when using magrittr in packages, e.g. something like

declare_dot <- function(add = TRUE) utils::globalVariables(".", add = add)

@jackwasey
Copy link

utils::globalVariables(c(".", "%>%")) works well for me in a package which uses magrittr for tests and data pre-processing, but not in user-facing functions: this means I can suggest instead of import magrittr without check complaining.

pierreroudier added a commit to pierreroudier/dissever that referenced this issue Sep 28, 2015
@smbache
Copy link
Member

smbache commented Feb 3, 2016

@gaborcsardi @jennybc I added a formula feature in this branch: https://github.com/smbache/magrittr/tree/simplified

You could then do

letters %>% 
  ~gsub("[a-k]", "z", .)

Small thing, but would make the checker happier..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants