[R] filename of current device

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Thu May 15 07:28:54 CEST 2014


You know, there is a more conventional way to handle this (at least from an R users perspective): Don't do that.

The normal method of analysis in R is to perform analysis computations in separate functions than the functions that display/print results. You can easily take this one step further and put your analysis functions in a separate R file than your display functions, and save the results (typically) to an RData file. That way your display operations can run at your convenience (interactively), and there is no concern that a pdf file sits there open for long periods.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

On May 14, 2014 4:43:31 PM PDT, Andreas Leha <andreas.leha at med.uni-goettingen.de> wrote:
>Hi David,
>
>David Winsemius <dwinsemius at comcast.net> writes:
>
>> On May 14, 2014, at 3:44 PM, Andreas Leha wrote:
>>
>>> Hi David,
>>> 
>>> Thank you for following up on that.
>>> 
>>> David Winsemius <dwinsemius at comcast.net> writes:
>>> 
>>>> On May 14, 2014, at 3:04 PM, Andreas Leha wrote:
>>>> 
>>>>> Hi all,
>>>>> 
>>>>> how do I find out about the filename, the currently open (let's
>say pdf)
>>>>> device is writing to?
>>>>> 
>>>>> If I find 'dev.cur()' returning 'pdf 3' when I expect 'nulldevice
>1' I
>>>>> would like to know, which file that pdf device is actually
>targeting.
>>>>> 
>>>>> Any help for my poor organization is highly appreciated...
>>>>> 
>>>> 
>>>> Have your read the help file for pdf()? The first argument is the
>default naming mechanism:
>>>> 
>>>> file = ifelse(onefile, "Rplots.pdf", "Rplot%03d.pdf")
>>>> 
>>>> So if you call pdf() then it will write to the working directory
>with a named constructed from those choices.
>>>> 
>>> 
>>> Sorry for being unclear.  I am aware of that.  My use case is, that
>>> apparently, I have called pdf("somefile.pdf") somewhen during a long
>>> lasting R session.
>>> 
>>> I tend to have separate R sessions open in parallel
>>> for the project I am working on.  So, I can easily have R session
>open
>>> that run for weeks.
>>> 
>>> So, when I return to an R session (when I got some additional data,
>I
>>> was asking for, e.g.) after several days, I do not know what that
>call
>>> was.  And for several reasons, the actual call (pdf("somefile.pdf"))
>>> might not even be visible in my R session.
>>> 
>>> In that situation, I would like to know, which is the open file for
>the
>>> current device.
>>
>> Well, if you acheived success with the pdf() call by executing
>> dev.off() then you closed that device. The previous device does leave
>> behind a footprint but not the entire name of hte file or the
>> contents.
>>
>> ?dev.prev
>>
>>> old.dev <-dev.prev()
>>> str(old.dev)
>>  Named int 5
>>  - attr(*, "names")= chr "pdf"
>>
>>
>> If you had not changed working directory you may be able to then look
>> at all of the pdf files. You can get information with file,info()
>>
>> ?file.info
>>
>>
>
>Thanks for the follow-up.  I take it, there is no 'easy' way in R to
>achieve this.
>
>The best solution (on unix systems) that I have come up with is this:
>  system(paste("lsof -p", Sys.getpid(), "| grep pdf"))
>(which obviously works only before dev.off())
>
>I was hoping for some more reliable way to achieve this, but it'll work
>for me.
>
>Thanks again,
>Andreas
>
>______________________________________________
>R-help at r-project.org 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.



More information about the R-help mailing list