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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:39:42+00:00 2026-05-27T06:39:42+00:00

In R, the idiomatic way to call another function without evaluating the parameters you

  • 0

In R, the idiomatic way to call another function without evaluating the parameters you give it is apparently as follows:

Call <- match.call(expand.dots = TRUE)
# Modify parameters here as needed and set unneeded ones to NULL.
Call[[1L]] <- as.name("name.of.function.to.be.called.here")
eval.parent(Call)

However, when I put a namespaced name (e.g. utils::write.csv) in the as.name() call, I get an error:

“could not find function “utils::write.csv”

What is the proper way of using this R idiom to call a namespaced function?

  • 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-05-27T06:39:43+00:00Added an answer on May 27, 2026 at 6:39 am

    Here is a solution using do.call(), which both constructs and evaluates the function call.

    Like the approach you started with, this one uses the fact that R calls are lists in which: (a) the first element is the name of a function; and (b) all following elements are arguments to that function.

    j <- function(x, file) {
        Call <- match.call(expand.dots = TRUE)
        arglist <- as.list(Call)[-1]
        do.call(utils::write.csv, arglist)
    }
    
    dat <- data.frame(x=1:10, y=rnorm(10))
    
    j(dat, file="outfilename.csv")
    

    EDIT: FWIW, here’s an example from plot.formula in base R, which uses a construct similar to the one above:

    {
        m <- match.call(expand.dots = FALSE)
        eframe <- parent.frame()
        . . .
        . . . 
        m <- as.list(m)
        m[[1L]] <- stats::model.frame.default
        m <- as.call(c(m, list(na.action = NULL)))
        mf <- eval(m, eframe)
        . . .
        . . . 
    }
    

    The function uses the do.call() construct later on. Going a bit deeper into the weeds, my reading is that in the snippet shown here, it instead uses several steps mostly because of the need to add na.action=NULL to the list of arguments.

    In any case, it looks like the do.call() options is as close to canonical as could be desired.

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

Sidebar

Related Questions

Is there an idiomatic way to bind variables in a MATLAB function? It seems
What's the idiomatic way to do maximumBy (higher order function taking a comparison function
What would be an idiomatic way of executing a function within a time limit?
What is the idiomatic way to create an infinite loop? while(true){ calc(); } I
Is there a idiomatic way of removing elements from PATH-like shell variables? That is
What is the Ruby idiomatic way for retrieving a single character from a string
What is the most idiomatic way to do the following? def xstr(s): if s
What would be the most idiomatic way to do the following in JavaScript: If
I'm looking for a much more idiomatic way to do the following little ruby
In Java, the idiomatic way to declare critical sections in the code is 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.