device error pdf

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

device error pdf

Christian Hoffmann-2
Hi,

Iwrote 'pdfc' in analogy to 'lpr':

pdfc <- function (file = "Rplot.pdf") {
   current.device <- dev.cur()
   dev.off(dev.copy(device = pdf, file = file, ...))
   dev.set(current.device)
   print(paste(file, "generated."))
   }

lpr <- function (object, file = "Rplotlpr.ps", ...)
{
     if (missing(object)) {
         current.device <- dev.cur()
         dev.off(dev.copy(device = postscript, file = file, ...))
         dev.set(current.device)
         system(paste("lpr", file))
         print(paste(file, "printed."))
     }
     else {
         if (missing(file))
             file <- "Robjlpr.txt"
         sink(file)
         object <- as.character(substitute(object))
         print(get(object))
         sink()
         system(paste("lpr", file))
         print(paste(object, "printed."))
     }
}

Now, while
 
> lpr()
[1] "Rplotlpr.ps printed."

is working almost fine (the plot window of Quartz-2 is not sized correctly, what would you suggest, Ray Brownrig \email{[hidden email]} ?),

with > pdfc()

I get

Error in dev.off(dev.copy(device = pdf, file = file, ...)) :
   '...' used in an incorrect context

I searched the Web, but found no hint how to avoid  this error. So the culprit could be

device = pdf

On the other hand  executing

> pdf()

generates the file

Rplotlpr.ps

but this very small and causes the Adobe Reader to say

This file is damaged and cannot be opened.


Thanks for help.

Chirsitan HOffmann

--
Christian W. Hoffmann,
CH - 8915 Hausen am Albis, Switzerland
Rigiblickstrasse 15 b, Tel.+41-44-7640853
[hidden email],
[hidden email],
www.echoffmann.ch

______________________________________________
[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: device error pdf

Duncan Murdoch-2
On 12-10-08 9:39 AM, Christian Hoffmann wrote:

> Hi,
>
> Iwrote 'pdfc' in analogy to 'lpr':
>
> pdfc <- function (file = "Rplot.pdf") {
>     current.device <- dev.cur()
>     dev.off(dev.copy(device = pdf, file = file, ...))
>     dev.set(current.device)
>     print(paste(file, "generated."))
>     }
>
> lpr <- function (object, file = "Rplotlpr.ps", ...)
> {
>       if (missing(object)) {
>           current.device <- dev.cur()
>           dev.off(dev.copy(device = postscript, file = file, ...))
>           dev.set(current.device)
>           system(paste("lpr", file))
>           print(paste(file, "printed."))
>       }
>       else {
>           if (missing(file))
>               file <- "Robjlpr.txt"
>           sink(file)
>           object <- as.character(substitute(object))
>           print(get(object))
>           sink()
>           system(paste("lpr", file))
>           print(paste(object, "printed."))
>       }
> }
>
> Now, while
>
>> lpr()
> [1] "Rplotlpr.ps printed."
>
> is working almost fine (the plot window of Quartz-2 is not sized correctly, what would you suggest, Ray Brownrig \email{[hidden email]} ?),
>
> with > pdfc()
>
> I get
>
> Error in dev.off(dev.copy(device = pdf, file = file, ...)) :
>     '...' used in an incorrect context

You can't use ... in a function unless you use it in the header of the
function.


>
> I searched the Web, but found no hint how to avoid  this error. So the culprit could be

You shouldn't look for obscure meanings:  the error means just what it
says.  You used ... in an incorrect context.  So you should examine the
context in which you used it, and figure out why ... is incorrect there.

Duncan Murdoch

>
> device = pdf
>
> On the other hand  executing
>
>> pdf()
>
> generates the file
>
> Rplotlpr.ps
>
> but this very small and causes the Adobe Reader to say
>
> This file is damaged and cannot be opened.
>
>
> Thanks for help.
>
> Chirsitan HOffmann
>

______________________________________________
[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: device error pdf

Rui Barradas
In reply to this post by Christian Hoffmann-2
Hello,

Without looking to much at your function pdfc(), it is obvious to me
that the error comes not from what the function does or does not, but
from not having dots '...' as a formal argument.
Simply put, you can only use '...' inside a function if it's a formal
argument to that function.

Try pdfc <- function (file = "Rplot.pdf", ...) and see what happens.

Hope this helps,

Rui Barradas

Em 08-10-2012 14:39, Christian Hoffmann escreveu:

> Hi,
>
> Iwrote 'pdfc' in analogy to 'lpr':
>
> pdfc <- function (file = "Rplot.pdf") {
>   current.device <- dev.cur()
>   dev.off(dev.copy(device = pdf, file = file, ...))
>   dev.set(current.device)
>   print(paste(file, "generated."))
>   }
>
> lpr <- function (object, file = "Rplotlpr.ps", ...)
> {
>     if (missing(object)) {
>         current.device <- dev.cur()
>         dev.off(dev.copy(device = postscript, file = file, ...))
>         dev.set(current.device)
>         system(paste("lpr", file))
>         print(paste(file, "printed."))
>     }
>     else {
>         if (missing(file))
>             file <- "Robjlpr.txt"
>         sink(file)
>         object <- as.character(substitute(object))
>         print(get(object))
>         sink()
>         system(paste("lpr", file))
>         print(paste(object, "printed."))
>     }
> }
>
> Now, while
>
>> lpr()
> [1] "Rplotlpr.ps printed."
>
> is working almost fine (the plot window of Quartz-2 is not sized
> correctly, what would you suggest, Ray Brownrig
> \email{[hidden email]} ?),
>
> with > pdfc()
>
> I get
>
> Error in dev.off(dev.copy(device = pdf, file = file, ...)) :
>   '...' used in an incorrect context
>
> I searched the Web, but found no hint how to avoid  this error. So the
> culprit could be
>
> device = pdf
>
> On the other hand  executing
>
>> pdf()
>
> generates the file
>
> Rplotlpr.ps
>
> but this very small and causes the Adobe Reader to say
>
> This file is damaged and cannot be opened.
>
>
> Thanks for help.
>
> Chirsitan HOffmann
>

______________________________________________
[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.