0

I want to temporarily modify the function lattice:::print.trellis. I can use edit to open the function code in editor but changes will be discarded after exit the editor (not the R session). I also tried fix but met the following error:

> fix(lattice:::print.trellis)
Error in fix(lattice:::print.trellis) : 'fix' requires a name
>

Can anybody explain the error? Is there anyway to modify this invisible function conveniently and temporarily (only effective in the current session)?

BTW, the lattice library is already loaded.

RNA
  • 146,987
  • 15
  • 52
  • 70
  • I'd read that you need to re-create the package to persist your changes. I need to do similar but am not keen on such an involved process for a change so minor. – Matt Weller Mar 22 '14 at 07:48
  • @flodel cleared the confusion in the question. – RNA Mar 22 '14 at 16:34
  • I strongly recommend you copy the source to `print.trellis` and create a `myprint.trellis` . Modifying package functions will muck things up one day when you don't expect it (you'll have forgotten the mod is there). – Carl Witthoft Mar 22 '14 at 16:49

1 Answers1

1

There are functions assignInNamespace and fixInNamespace that allow doing what you say. There is also the edit argument to the trace function which will let you edit a function in place. Using trace has the advantage of making it easy to untrace and remove the changes that you made.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110