3

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 ?

micstr
  • 5,080
  • 8
  • 48
  • 76
  • 2
    You need to import these functions in your NAMESPACE. Instead of doing it manually, check out the `roxygen2` package and the `devtools::document` functions and [this link](http://r-pkgs.had.co.nz/man.html). – csgroen Jul 28 '20 at 14:23
  • so i have to get the code source for all these functions and to put them in NAMESPACE? – Emilie Sechere Jul 28 '20 at 14:27
  • No. Please read the references I've sent. You can import them while writing your documentation. – csgroen Jul 28 '20 at 14:40

1 Answers1

6

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.

Peter D
  • 171
  • 5