Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no visible global function definition for '%>%'

Tags:

r

devtools

I'm trying to build a devtools package, and I need to use this loop in my code :

for (i in 1:length(idk)){
  tritemp=intetemp[intetemp$path %in% idk[i],]
  tritemp=tritemp %>%
    group_by(grp = paste(pmax(from, to), pmin(from, to), sep = "_")) %>%
    slice(1) %>%
    ungroup() %>%
    select(-grp)
  interac=rbind(interac,tritemp)
}

Unfortunately when I run the devtools check I get these errors :

interactions: no visible global function definition for '%>%'
  interactions: no visible binding for global variable 'from'
  interactions: no visible binding for global variable 'to'
  interactions: no visible global function definition for 'slice'
  interactions: no visible global function definition for 'ungroup'
  interactions: no visible global function definition for 'select'
  interactions: no visible binding for global variable 'grp'
  Undefined global functions or variables:
    %>% from grp select slice to ungroup

I really don't know what to do with this, can someone help me ?

like image 202
Emilie Sechere Avatar asked Oct 19 '25 05:10

Emilie Sechere


1 Answers

These are all functions from different packages. You need to specify where these functions come from. For the pipe function specifically, you need to put magrittr under the imports section in your DESCRIPTION file. Then in the script that uses the pipe you can put

#' @importFrom magrittr %>%
NULL

if you are using roxygen2 to automatically have it add that function to your NAMESPACE You will have to do this for every function you use from another package.

Alternative to using the @importFrom ... at the top you can go through your script and specify what package the function you are using is coming from. e.g. dplyr::select(yourvariables)

This is a bit much to explain in detail in a single answer here, so I'd recommend reading this to get a better understanding.

like image 140
Peter D Avatar answered Oct 21 '25 19:10

Peter D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!