Skip to content
Discussion options

You must be logged in to vote

I suppose you use bind_rows() in a function? Instead of loading the package at the top of the script, you should load the package inside the function. See the example below. Note that I use require() instead of library(). require() loads the package as library() does but it returns a TRUE or FALSE depending on R was able to load the package. Wrapping that instead of a stopifnot() ensures that your function errors when then package is not available.

An alternative is to use the package::function notation. E.g. dplyr::bind_rows().

my_fun <- function(x, y) {
  stopifnot(require("dplyr"))
  bind_rows(x, y)
}

In case of %>%, it is easier to replace it with the base pipe |>.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@w-jan
Comment options

Answer selected by w-jan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants