Can I set default parameters for the default graphics device?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Can I set default parameters for the default graphics device?

jumpfroggy
I'm completely new to R, and I'd like to do something like this:

    > x=c(1,2,3)
    > plot(x,x)

At this point, R creates a file "Rplots.pdf", since the default device is
PDF and the default filename is "Rplots.pdf".  I know I can set the default
device like this:

    > options(device="png")

But is there a way to set the default device's default filename?

Thanks!

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Can I set default parameters for the default graphics device?

Sam Albers
Unless you aren't writing scripts why wouldn't you just use something like this?

> x=c(1,2,3)
> pdf("RRules.pdf")
> plot(x,x)
> dev.off()
Reply | Threaded
Open this post in threaded view
|

Re: Can I set default parameters for the default graphics device?

Erik Iverson-3
In reply to this post by jumpfroggy
On 07/15/2010 07:10 PM, James wrote:
> I'm completely new to R, and I'd like to do something like this:
>
>      >  x=c(1,2,3)
>      >  plot(x,x)
>
> At this point, R creates a file "Rplots.pdf", since the default device is
> PDF and the default filename is "Rplots.pdf".

Since you're completely new to R, I might ask what OS you're using, and if
you're using R interactively?  If you are using R interactively, the default
device would probably create a new 'window' to display the graphic in.  If
you're running in batch mode, then pdf is the default.


I know I can set the default
> device like this:
>
>      >  options(device="png")
>
> But is there a way to set the default device's default filename?

I guess you can probably just write your own wrapper function and use that as
the device name.

Try:

mypng <- function(filename = "mydefault.png", ...) {
    png(filename, ...)
}

options(device = "mypng")

I did not test any of this, but I hope it works.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Can I set default parameters for the default graphics device?

jumpfroggy
In reply to this post by Sam Albers
On Thu, Jul 15, 2010 at 8:36 PM, Sam Albers <[hidden email]>wrote:

> Unless you aren't writing scripts why wouldn't you just use something like
> this?
>

I'm writing scripts, and this is a convenience feature I'm trying to
implement.  I know it can be done manually, but I'd love to be able to set
the default name for output images.
-James

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Can I set default parameters for the default graphics device?

jumpfroggy
In reply to this post by Erik Iverson-3
On Thu, Jul 15, 2010 at 8:43 PM, Erik Iverson <[hidden email]>  wrote:
> On 07/15/2010 07:10 PM, James wrote:
>> I'm completely new to R, and I'd like to do something like this:
>>     >  x=c(1,2,3)
>>     >  plot(x,x)
>> At this point, R creates a file "Rplots.pdf", since the default device is
>> PDF and the default filename is "Rplots.pdf".
>
> Since you're completely new to R, I might ask what OS you're using, and if
you're using R interactively?  If you are using R interactively, the default
device would probably create a new 'window' to display the graphic in.  If
you're running in batch mode, then pdf is the default.

Sorry for the lack of details.  I'm running R non-interactively (so the
default device is the "pdf" one), and I'm running on linux.

> I guess you can probably just write your own wrapper function and use that
as the device name.
> Try:
> mypng <- function(filename = "mydefault.png", ...) {
>   png(filename, ...)
> }
> options(device = "mypng")
> I did not test any of this, but I hope it works.

That definitely is an option, and if I can't figure out a way to change the
default then I might go with a wrapper function like that.

My goal is to make sure that I can choose the default name for any output
images.  In a normal script, you can just start plotting things (like in my
example) without creating a device or setting the graphics driver first.  It
just uses the default.  I can change the default device, but my goal is also
to change the default filename as well.

So instead of:

    > mypng()
    > x=c(1,2,3)
    > plot(x,x)

I can just do:

    > x=c(1,2,3)
    > plot(x,x)

Thanks for the help so far!
-James

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Can I set default parameters for the default graphics device?

Erik Iverson-3
<snip>

> So instead of:
>
>  > mypng()
>  > x=c(1,2,3)
>  > plot(x,x)
>
> I can just do:
>
>  > x=c(1,2,3)
>  > plot(x,x)

Isn't that what you can do after you define mypng and set

options(device = "mypng")

?

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Can I set default parameters for the default graphics device?

jumpfroggy
Erik,

On Thu, Jul 15, 2010 at 9:27 PM, Erik Iverson <[hidden email]> wrote:
> Isn't that what you can do after you define mypng and set
> options(device = "mypng")

Thank you!  I completely missed the second part where you use that as
the default device.  I must have skimmed your email.

I'm definitely going to try this, thanks in advanced!  I'm excited,
maybe I'll finally get passed this hurdle. :)

-James

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.