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

  • Home
  • SEARCH
  • 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 7892073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:46:41+00:00 2026-06-03T06:46:41+00:00

I have a R script to load multiple text files in a directory and

  • 0

I have a R script to load multiple text files in a directory and save the data as compressed .rda. It looks like this,

#!/usr/bin/Rscript --vanilla

args <- commandArgs(TRUE)
## arg[1] is the folder name

outname <- paste(args[1], ".rda", sep="")

files <- list.files(path=args[1], pattern=".txt", full=TRUE)

tmp <- list()
if(file.exists(outname)){
  message("found ", outname)
  load(outname)
  tmp <- get(args[1]) # previously read stuff
  files <- setdiff(files, names(tmp))

}

 if(is.null(files)) 
    message("no new files") else {

## read the files into a list of matrices
results <- plyr::llply(files, read.table, .progress="text")
names(results) <- files

assign(args[1], c(tmp, results))
message("now saving... ", args[1])
save(list=args[1], file=outname)
}
message("all done!")

The files are quite large (15Mb each, 50 of them typically), so running this script takes up to a few minutes typically, a substantial part of which is taken writing the .rda results.

I often update the directory with new data files, therefore I would like to append them to the previously saved and compressed data. This is what I do above by checking if there’s already an output file with that name. The last step is still pretty slow, saving the .rda file.

Is there a smarter way to go about this in some package, keeping a trace of which files have been read, and saving this faster?

I saw that knitr uses tools:::makeLazyLoadDB to save its cached computations, but this function is not documented so I’m not sure where it makes sense to use it.

  • 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-03T06:46:42+00:00Added an answer on June 3, 2026 at 6:46 am

    For intermediate files that I need to read (or write) often, I use

    save (..., compress = FALSE)
    

    which speeds up things considerably.

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

Sidebar

Related Questions

I have this code: <div id=gll_select> <script> var caffe = $(#caffe).val(); $(#gll_select).load(<?php echo base_url()
I have script like this : fullscript.sh if [ ! -f /opt/laks/linux-2.6.33.2.tar.bz2 ] then
I have a script that drops a load of tables using DROP TABLE IF
I have a script on jquery that load some site in iframe using: $(#demo_frame).attr('src',
I have a java script function that i have called on body load mousemove()
I have created an R script that it needs to load some libraries first.
well im using this script right here: http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/ and I have a multiMonth plugin
I have a need to either have multiple script managers on a page or
i have this simple script of a popunder window: function loadpopunder(){ win2=window.open(popunder,,winfeatures) win2.blur() window.focus()
I have this button with which I want to send data back to the

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.