Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6878439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:43:25+00:00 2026-05-27T04:43:25+00:00

When I use Sweave with R , I can avoid explicitly naming the plot

  • 0

When I use Sweave with R, I can avoid explicitly naming the plot files by simply enclosing the plot commands within a code-chunk like <<fig=TRUE>> ... @. The Sweave driver automatically generates numbered plot files like fig1.pdf, fig2.pdf, etc.

However in org-mode, it seems like I need to explicitly name the figure file using a :file [...].pdf in the header, e.g.

#+attr_latex: width=8cm placement=[htbp]
#+begin_src R :results output graphics :exports results :file fig.pdf                                                                                                                                                                                                 
    require(ggplot2)                                                                                                                           
    a <- rnorm(100)                                                                                                                            
    b <- 2*a + rnorm(100)                                                                                                                      
    d <- data.frame(a,b)                                                                                                                       
    ggplot(d,aes(a,b)) + geom_point()                                                                                                          
#+end_src                                     

Is there some way to avoid explicitly naming the plot file, and have the org-mode latex export engine generate these file-names?

Update: I’m including the solution that G. Jay Kerns pointed to here for easy reference: all you need to do is include a temp-file-generating emacs-lisp function in the header, like :file (org-babel-temp-file "./figure-" ".pdf"). This creates a temp figure-file in the current directory (because of the ./). If you want the temp figure-file in a global temp directory (defined by the variable org-babel-temporary-directory), then just say ".figure":

#+attr_latex: width=8cm placement=[htbp]
#+begin_src R :results output graphics :exports results :file (org-babel-temp-file "./figure-" ".pdf")                                                                                                                                                                                                 
    require(ggplot2)                                                                                                                           
    a <- rnorm(100)                                                                                                                            
    b <- 2*a + rnorm(100)                                                                                                                      
    d <- data.frame(a,b)                                                                                                                       
    ggplot(d,aes(a,b)) + geom_point()                                                                                                          
#+end_src                                     
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:43:26+00:00Added an answer on May 27, 2026 at 4:43 am

    Great question, and a similar one (plus some extra stuff) came up on the Org-mode mailing list back in September. The original question is here, and a sketch of a possible solution lies in the final message of the thread here (see #1, the other items are about other things).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this code to make figures in Sweave <<label=fig1plot, include=FALSE >>= plot(cars) @
I am working on Sweave now, when I want to use R code to
Use case: user clicks the link on a webpage - boom! load of files
I have a rather large chunk of code that breaks sometimes, as far as
I'm trying to use Sweave to generate a statistical report, and am trying to
I would like to find a way to use the LaTeX \ref{} markup to
I would like to write figure captions in the R mode of Sweave and
Use case example: Client A comes to request sales information, enters their zip code
How can I produce a Sweave (or pgfSweave) document without angle brackets > in
how to configure Sweave it's work and recognize for Rpy2? I use this import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.