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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:11:40+00:00 2026-06-11T08:11:40+00:00

I am trying to source multiple functions, that differ by a number in the

  • 0

I am trying to source multiple functions, that differ by a number in the name.

For example: func1, func2.

I tried using “func_1”, and “func_2”, as well as putting the number first, “1func” and “2func”. No matter how I index the function names, the source function just reads in one function that it calls "func" – which is not what I want.

I have tried using for-loops and sapply:

for-loop:

func.list <- list.files(path="/some_path",pattern="some pattern",full.names=TRUE)
for(i in 1:length(func.list)){
source(func.list[i])
}

sapply:

sapply(func.list,FUN=source)

I am going to be writing multiple versions of a data correction function, and would really like to be able to index them – because giving a concise, but specific, name would be difficult, and not allow me to selectively source just the function files from their directory.

In my code, func.list gives the output (I have replaced the actual directory because of privacy/contractual issues):

[1] "mypath/1resp.correction.R" 
[2] "mypath/2resp.correction.R"

Then when I source func.list with either the for-loop or sapply code (listed above), R only loads one function named resp.correction, with the code body from “2resp.correction.R”.

  • 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-11T08:11:42+00:00Added an answer on June 11, 2026 at 8:11 am

    The argument to source is a file name, not a function name. So you cannot be fancy here: you need to provide the exact filenames.

    It sounds like your two files contain the definitions of a function with the same name (resp.correction) in both files, so yes, as you source one file after the other, the function is overwritten in your global environment.

    You could, inside your loop, reassign the function to a different name:

    func.list <- list.files(path="/some_path",pattern="some pattern",full.names=TRUE)
    for(i in 1:length(func.list)) {
       source(func.list[i], local = TRUE)
       assign(paste0("resp.correction", i), resp.correction, envir = .GlobalEnv)
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to first .getJSON then using that data to become the source of my
i'm using the source code for multiple selection Dropdown check-list Since, the example has
I'm trying to make a chart, with multiple columns as source area. Basically, I
I am trying to code a widget that collates Tweets from multiple sources as
The C source codes that I am trying to port into 64 bit runs
I am trying to retrieve the image source of an image that the user
I'm trying to find open source profilers rather than using one of the commercial
I am trying to update a source image with the contents of multiple destination
I'm currently trying to implement a UITableView with a delegate and data source that
Using jQ UI Autocomplete with multiple values My function looks like that mailto_input.bind( keydown,

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.