Error in function (file = ifelse(onefile, "Rplots.pdf", "Rplot%03d.pdf") cannot open file 'Rplots.pdf',

3,239 views
Skip to first unread message

SantoshMarigowda

unread,
Jul 6, 2012, 6:29:06 AM7/6/12
to rap...@googlegroups.com
Hi,

I am trying to generate a simple plot.

<Location /rapachetest>
        SetHandler r-handler
        RFileHandler /var/www/R/hello.R
</Location>

[perf@localhost ~]$ cat /var/www/R/hello.R
print("Welcome to R Web Development")
x <- c(1,3,6,9,12)
y <- c(1.5,2,7,8,15)
plot(x,y)
[perf@localhost ~]$

When I send a request http://localhost/rapachetest, I see the following error in apache logs. I have tested this code standalone (just using R) and it works.

----
==> error_log <==
[Fri Jul 06 11:23:20 2012] [error] [client 127.0.0.1] rApache Notice!
Error in function (file = ifelse(onefile, "Rplots.pdf", "Rplot%03d.pdf"),  :
  cannot open file 'Rplots.pdf'
Traceback:
4: function (file = ifelse(onefile, "Rplots.pdf", "Rplot%03d.pdf"),
       width, height, onefile, family, title, fonts, version, paper,
       encoding, bg, fg, pointsize, pagecentre, colormodel, useDingbats,
       useKerning, fillOddEven, maxRasters, compress)
   {
       initPSandPDFfonts()
       new <- list()
       if (!missing(width))
           new$width <- width
       if (!missing(height))
           new$height <- height
       if (!missing(onefile))
           new$onefile <- onefile
       if (!missing(title))
           new$title <- title
       if (!missing(fonts))
           new$fonts <- fonts
       if (!missing(version))
           new$version <- version
       if (!missing(paper))
           new$paper <- paper
       if (!missing(encoding))
           new$encoding <- encoding
       if (!missing(bg))
           new$bg <- bg
       if (!missing(fg))
           new$fg <- fg
       if (!missing(pointsize))
           new$pointsize <- pointsize
       if (!missing(pagecentre))
           new$pagecentre <- pagecentre
       if (!missing(colormodel))
           new$colormodel <- colormodel
       if (!missing(useDingbats))
           new$useDingbats <- useDingbats
       if (!missing(useKerning))
           new$useKerning <- useKerning
       if (!missing(fillOddEven))
           new$fillOddEven <- fillOddEven
       if (!missing(maxRasters))
           warning("'maxRasters' is no longer needed, and will be ignored")
       if (!missing(compress))
           new$compress <- compress
       old <- check.options(new, name.opt = ".PDF.Options", envir = .PSenv)
       if (!missing(family) && (inherits(family, "Type1Font") ||
           inherits(family, "CIDFont"))) {
           enc <- family$encoding
           if (inherits(family, "Type1Font") && !is.null(enc) &&
               enc != "default" && (is.null(old$encoding) || old$encoding ==
               "default"))
               old$encoding <- enc
           family <- family$metrics
       }
       if (is.null(old$encoding) || old$encoding == "default")
           old$encoding <- guessEncoding()
       if (!missing(family)) {
           if (length(family) == 4L) {
               family <- c(family, "Symbol.afm")
           }
           else if (length(family) == 5L) {
           }
           else if (length(family) == 1L) {
               pf <- pdfFonts(family)[[1L]]
               if (is.null(pf))
                   stop(gettextf("unknown family '%s'", family),
                     domain = NA)
               matchFont(pf, old$encoding)
           }
           else stop("invalid 'family' argument")
           old$family <- family
       }
       version <- old$version
       versions <- c("1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7",
           "2.0")
       if (version %in% versions)
           version <- as.integer(strsplit(version, "[.]")[[1L]])
       else stop("invalid PDF version")
       onefile <- old$onefile
       if (!checkIntFormat(file))
           stop("invalid 'file'")
       .External(PDF, file, old$paper, old$family, old$encoding,
           old$bg, old$fg, old$width, old$height, old$pointsize,
           onefile, old$pagecentre, old$title, old$fonts, version[1L],
           version[2L], old$colormodel, old$useDingbats, old$useKerning,
           old$fillOddEven, old$compress)
       invisible()
   }()
3: dev.hold()
2: plot.default(x, y)
1: plot(x, y)

==> access_log <==
127.0.0.1 - - [06/Jul/2012:11:23:20 +0100] "GET /rapachetest HTTP/1.1" 500 534 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2"


---

Could you please help?

Regards
Santosh


SantoshMarigowda

unread,
Jul 6, 2012, 6:36:21 AM7/6/12
to rap...@googlegroups.com
I think I need to set the content type. Let me try.

Regards
Santosh

SantoshMarigowda

unread,
Jul 6, 2012, 7:30:21 AM7/6/12
to rap...@googlegroups.com
This issue is solved by setting content type:

[root@localhost R]# cat /var/www/R/hello.R.2
setContentType("image/png")
t <- tempfile()

x <- c(1,3,6,9,12)
y <- c(1.5,2,7,8,15)
png(t,type="cairo")
plot(x,y)
dev.off()
sendBin(readBin(t,'raw',n=file.info(t)$size))
unlink(t)
DONE

Regards
Santosh

E.Y. Fang

unread,
Nov 16, 2017, 1:12:20 AM11/16/17
to rapache
Hi, I'm having the same error, but trying setContentType() didn't fix it. When I ran it, it says
 could not find function "setContentType"
Reply all
Reply to author
Forward
0 new messages