1

I'm writing an R package, where users are expected to run transform the data with my function in the way that is bound to fail. I want to add two examples to this function - one where the "default" run throws an error, and the second where the data is quite aggressively filtered (can't make this a default).

How do I add the example for the first case, where the code is bound to fail?

JelenaČuklina
  • 3,574
  • 2
  • 22
  • 35
  • 1
    Either wrap it in `try` or `tryCatch`, or more likely, tell roxygen not to run the example, [as here](https://stackoverflow.com/q/12038160/903061) (possible duplicate). – Gregor Thomas Jun 17 '19 at 14:46
  • @Gregor, I'd not say it's a duplicate since it's the error-generating example on purpose, it doesn't matter if it is run or not, but the more common practice seems to have it within `\dontrun{}` – JelenaČuklina Jun 18 '19 at 09:48
  • Then I don't understand why you think it is not a duplicate? The top answer at the dupe is to have it within `\dontrun{}`, the next answer suggests `\donttest{}`. If those answers don't work for you, why not? What behavior do you want instead? – Gregor Thomas Jun 18 '19 at 12:32

1 Answers1

1

You can add it within a \dontrun{} block so that it does not cause errors. http://r-pkgs.had.co.nz/man.html#man-functions

timcdlucas
  • 1,334
  • 8
  • 20