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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:59:30+00:00 2026-06-02T15:59:30+00:00

I have two folders, folder1 and folder2 with around 200 files each that are

  • 0

I have two folders, folder1 and folder2 with around 200 files each that are either *rda or *R. I want to read all of the files and datasets from the two directories. How can I do that?

Paths for:

folder1:  C:\folder1
folder2:  C:\folder2 

My trial

setwd("C:/folder1")
myls <- ls() # do work as this will only list that are already loaded in the system 
setwd("C:/folder2")
myls2 <- ls()
myls  # do work as this will only list that are already loaded in the system 

I know this is simple question, but I do not have any answer.

  • 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-02T15:59:31+00:00Added an answer on June 2, 2026 at 3:59 pm

    Since .rda requires load and .R requires source, I would do something like this:

    file.sources = list.files(pattern="*.R")
    data.sources = list.files(pattern="*.rda")
    sapply(data.sources,load,.GlobalEnv)
    sapply(file.sources,source,.GlobalEnv)
    

    Update for reading from multiple folders at once

    file.sources = list.files(c("C:/folder1", "C:/folder2"), 
                              pattern="*.R$", full.names=TRUE, 
                              ignore.case=TRUE)
    data.sources = list.files(c("C:/folder1", "C:/folder2"),
                              pattern="*.rda$", full.names=TRUE, 
                              ignore.case=TRUE)
    sapply(data.sources,load,.GlobalEnv)
    sapply(file.sources,source,.GlobalEnv)
    

    Notice also the use of $ at the end of the search pattern, to make sure it matches only, say, a .R at the end of a line, and the use of ignore.case in case some of the files are named, say, script.r.

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

Sidebar

Related Questions

I have two set of folders that have files with the same filenames and
I have a TFS Project with two main folders: Project --Folder1 ----LibraryA --Folder2 ----AppA
Have two folders with approx. 150 java property files. In a shell script, how
I have wrote an application that syncs two folders together. The problem with the
I have two folders each which contain a lot of subfolders. Most of the
I have moved all of my files from being in the root (no folders,
I have two folders, for arguments sake /Volumes/A and /Volumes/B. They are mounted network
I have two folders php and perl . They contain index.php and index.pl ,
in /usr/local i now have two mysql folders: mysql-5.1.34-osx10.5-x86 mysql-5.1.37-osx10.5-x86_64 is it possible to
I have used two GUIDs to open the folders My Computer and My Documents

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.