1

I'd like to change default plot option from type = "p" to type = "l" ; I mean I want it is like that at the beginning of each new session, without specifying it any more.

I've tried to put some piece of code in my Rprofile.site but unfortunately not the right one: firstly I wanted to use setDefaults but this package is deprecated; I also tried to set a hook but couldn't make it work.

Any ideas ?

thanks !

ClementWalter
  • 4,814
  • 1
  • 32
  • 54
  • That could have undesired consequences for functions using `plot` internally. You should define a `lplot` function instead. – Roland Jul 29 '15 at 12:23
  • Do you mean you didn't put the right code in your Rprofile, or you didn't put code in the right Rprofile? – Benjamin Jul 29 '15 at 12:23
  • @Roland : that makes sense, even though I do it manually with `fix(plot.default)` and never had any issue so far – ClementWalter Jul 29 '15 at 12:40
  • @Benjamin : yes I know how to edit the `Rprofile.site` file, but I didn't find what to write in it to get my result – ClementWalter Jul 29 '15 at 12:41

1 Answers1

1

This could be done by adding to your Rprofile

formals(plot.default)$type <- "l"

But that would be highly discouraged, for the reasons Roland states in his comment. A better solution would be to place this in your Rprofile:

lplot <- function(x, y, type = "l", ...){
    plot(x, y, type = type, ...)
}

This gives you the default you want, the ability to revert back to normal if wanted, and doesn't affect the existing plot function.

But this still comes with the downside of the lplot function seemingly appearing out of nowhere. Far better would be to put lplot in a package. Even if you load the package in the Rprofile, at least ?lplot will pull up something to indicate where it came from.

Benjamin
  • 16,897
  • 6
  • 45
  • 65
  • `formals` was exactly the function I was looking for. I understand the drawbacks for `plot` but this was also just a MWE for SO, I'd like to do it with some other functions. Thanks ! – ClementWalter Jul 29 '15 at 13:40
  • I got the error `Error “cannot do complex assignments in base namespace”`, do you know how to handle that ? – ClementWalter Jul 29 '15 at 14:14