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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:54:43+00:00 2026-06-17T05:54:43+00:00

I am facing a strange problem about do.call and curve : func1 <- function

  • 0

I am facing a strange problem about do.call and curve:

func1 <- function (m, n) {
  charac <- paste ("func2 <- function(x)", m, "*x^", n, sep = "")
  eval(parse(text = charac))
  return(func2)
}
func3 <- function (m, n) {
  my.func <- func1 (m, n)
  do.call("curve",list(expr = substitute(my.func)))
}

func1 constructs func2 and func3 plots the constructed func2.
But when I run func3, following error would be displayed:

> func3 (3, 6)
Error in curve(expr = function (x)  : 
  'expr' must be a function, or a call or an expression containing 'x'

However, while I run func1 and plot the output manually (without applying func3), func2 would be plotted:

my.func <- func1 (3, 6)
do.call("curve",list(expr = substitute(my.func)))

What happened here leads me to a confusion and I do not know why do.call can not plot func2 inside func3 local environment.

Thank you

  • 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-17T05:54:44+00:00Added an answer on June 17, 2026 at 5:54 am

    It is not a problem of do.call, but substitute which evaluate by default in the global environment.
    So
    you need to tell it in which environment substitution must occur. Here obviously in the local envir of func3.

    This should work:

     do.call("curve",list(expr = substitute(my.func,
                                               env = parent.frame())))
    

    Edit thanks Dwin

    As said in the comment substitute env Defaults to the current evaluation environment. So Why the code below works? The answer in the help of substitute

    formal argument to a function or explicitly created using
    delayedAssign(), the expression slot of the promise replaces the
    symbol. If it is an ordinary variable, its value is substituted,
    unless env is .GlobalEnv in which case the symbol is left unchanged.

    env = parent.frame(n=1) is equivalent to .GlobalEnv, that why the symbol (my.func) is left unchanged. So the correct answer would be :

    do.call("curve",list(expr = substitute(my.func,
                                                   env = .GlobalEnv)))
    

    To test , I open new R session :

    func1 <- function (m, n) {
      charac <- paste ("func2 <- function(x)", m, "*x^", n, sep = "")
      eval(parse(text = charac))
      return(func2)
    }
    func3 <- function (m, n) {
      my.func <- func1 (m, n)
    
      do.call("curve",list(expr = substitute(my.func,env = .GlobalEnv)))
    }
    

    Than I call

     func3(2,6)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing a strange problem on my Ubuntu Karmic system. When I call
I am facing a strange problem in array_push function of php. Lets see my
since today im facing a strange problem. When i start my app in my
I am facing a strange problem and have no idea how to fix this
I am facing a strange problem with my iphone. It shows available memory as
I am facing very strange problem. After debugging from my side, I thought to
I am facing a very strange problem where the same loop keeps giving me
I'm facing a apparently very strange problem (I must be doing something wrong, just
I'm facing this strange problem. I'm trying to read a file that is located
I am facing a strange problem with AVAudioRecorder. In my application i need 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.