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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:21:22+00:00 2026-06-13T04:21:22+00:00

I am writing tests for an R function that imports an xml file, settings.xml

  • 0

I am writing tests for an R function that imports an xml file, settings.xml.

Currently, when I write a test for functions that depend on the contents of foo.xml, including the function read.settings in the following example:

writeLines("<fee><fi><\fi>\fee>", con = "/tmp/foo.xml")
settings <- read.settings("/tmp/foo.xml")
file.remove("/tmp/foo.xml")

But a number of issues have come up related to making the test system-independent. For example, /tmp/ may not be writeable or an error in read.settings() leaves an orphaned file in the test directory, etc. This is a trivial example and I can think of ways around these issues, but I recall such a solution in an answer to a previous question, which I now can not find, in which the con is not a file but an object in memory. I am sure that there are many situations in which it would be useful not to actually write a file.

  • Is there a way to write and access a pseudo-file that only exists in memory?
  • where is the feature documented?
    ?connections appears to be a good lead, but it is not clear to me how to use the information provided

As follow up (but not to be too open-ended)

  • What are the primary uses of such a feature beyond what I described above?
  • Are situations in which this feature should not be used?
  • 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-13T04:21:22+00:00Added an answer on June 13, 2026 at 4:21 am

    Here’s a construct that might be helpful. tempfile() returns a valid name for a temporary file on any operating system, and the call to on.exit(unlink()) ensures that the temporary file gets removed, no matter what else happens.

    test1 <- function() {
        temp <- tempfile()
        on.exit(unlink(temp))
        writeLines("<fee><fi><\fi>\fee>", con = temp)
        settings <- readLines(temp)
        settings
    }
    
    test1()
    # [1] "<fee><fi><\fi>\fee>"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

currently im writing a test for a report function the more functionality the project
I am writing a function that tests for brokens links in an org-mode buffer:
I'm writing unit tests for a function that takes both an *args and a
I am writing a test for a function that downloads the data from an
I'm writing some unit tests and I have a lot of functions of the
I'm writing a logging function for automation unit test. html elements structure: <li> <strong>
I'm writing an upload function for ColdFusion of Wheels and need to unit test
I'm writing JUnit tests for a service that creates and acts on an entity
I am writing a python script that is used for continuous integration and test
I am writing unit tests for objects that are cloned, serialized, and/or written to

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.