5

I am working with the earlywarnings package, and would like to edit one of the functions written in the qda_ews function. I could do fix(...) but the function I would like to edit is for some reason not listed when I use fix.

The function is called generic_RShiny. Here is the link to the github (https://github.com/earlywarningtoolbox/earlywarnings-R/blob/master/earlywarnings/R/qda_ews.R).

How can I access the entire qda_ews.R code to make the changes I need?

lmo
  • 37,904
  • 9
  • 56
  • 69
Demetri Pananos
  • 6,770
  • 9
  • 42
  • 73
  • 1
    You can get the function code with `getAnywhere(generic_RShiny)`. To edit it, you could paste it into a R script file, make your edits, assign it to a new object (like `my_generic_RShiny`) then run your new version of the function. – eipi10 Jul 19 '16 at 18:36
  • If you want to have the edited function available in the future, you could either save the script of the edited function and then `source` it when you need it, or you could create your own version of the `earlywarnings` package with the edited version of the function and then install/load your custom version of the package. – eipi10 Jul 19 '16 at 18:41
  • Seems like part of the problem may be [`generic_RShiny` is not exported](https://github.com/earlywarningtoolbox/earlywarnings-R/blob/master/earlywarnings/NAMESPACE); have you tried appending `earlywarnings:::generic_RShiny` to your approach using `fix`? – MichaelChirico Jul 20 '16 at 21:37

1 Answers1

4

once the library is loaded, use

trace(name_of_function, edit = T)

but beware that the function will be modified permanently (until of course you reinstall the package)

baskcat
  • 135
  • 1
  • 9
  • I edited a function using this method, but it doesn't seem to work with knitting Rmd into html file. Is there another method I can use? – lil_barnacle Mar 25 '21 at 17:15
  • If you want to use the changed method with knitting from Rmd. Copy the method using @baskcat answer, then paste it into your Rmd and edit it. Then instead of calling the library function, call the method from your Rmd. – Nexgea May 18 '23 at 10:35