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 8231473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:30:19+00:00 2026-06-07T17:30:19+00:00

When storing plots in a pdf R generates a temporary file (e.g. /tmp/RtmpFKQqjI/pdf317d27df81a0 )

  • 0

When storing plots in a pdf R generates a temporary file (e.g. /tmp/RtmpFKQqjI/pdf317d27df81a0) for each plot. After drawing many plots into a pdf my /tmp partition runs out of memory and R stops working (my desktop also freezes).

Little code example:

for (i in 1:10) {
    pdf(file=paste(i, ".pdf", sep=""))
    plot(1:10)
    dev.off()
}

list.files(path=tempdir(), pattern="^pdf.", full.names=TRUE)
# [1] "/tmp/RtmpFKQqjI/pdf317d27df81a0" "/tmp/RtmpFKQqjI/pdf317d28ed0612"
# [3] "/tmp/RtmpFKQqjI/pdf317d295c2453" "/tmp/RtmpFKQqjI/pdf317d304bb025"
# [5] "/tmp/RtmpFKQqjI/pdf317d3332d7fe" "/tmp/RtmpFKQqjI/pdf317d3921428f"
# [7] "/tmp/RtmpFKQqjI/pdf317d4cf812ca" "/tmp/RtmpFKQqjI/pdf317d5082bebe"
# [9] "/tmp/RtmpFKQqjI/pdf317d560d326"  "/tmp/RtmpFKQqjI/pdf317d674b25ea"

(Same results for pdf(file="Rplots%03d.pdf"); for (i in 1:10) { ... }; dev.off().)

Why doesn’t R remove this temporary files after calling dev.off()?

As a workaround I add the following line after each dev.off():

unlink(list.files(path=tempdir(), pattern="^pdf.", full.names=TRUE))

Is there a better way?

  • 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-06-07T17:30:21+00:00Added an answer on June 7, 2026 at 5:30 pm

    I tend to agree with @stark that this is a (minor) bug in R’s pdf device implementation.

    One workaround is to instead use the cairo_pdf device, which produces essentially identical pdfs but does not leave extra files lying around in the temp directory.

    for (i in 1:2) {
        cairo_pdf(file=paste(i, ".pdf", sep=""))
        plot(1:10)
        dev.off()
    }
    list.files(path=tempdir(), pattern="^pdf.", full.names=TRUE)
    # character(0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Storing the current_user in a string after they submit a comment <%= f.text_field :commenter,
I asked this question yesterday about storing a plot within an object. I tried
I am automating the creation of a series of plots each of which is
I want to have a single .plt file storing both data and gnuplot commands.
My application is fed data from an external device. After each data point, there
In the plot generated by ggplot, each label along the x-axis is a string,
sorry am having bit of trouble here storing scraped content into MYSQL database. So
I am trying to plot a pie chart from a .txt file with data-set
I want to plot (i.e. write a file) with matplotlib from a script that
Storing credit card information securely and legally is very difficult and should not be

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.