Bak_was
Bak_was

Reputation: 45

r :Error: could not find function -User defined

I am trying to run the below simple function in R studio

    a<-testfunc15(state,outcome)
           {

            st<-state
            out<-outcome 
             print(st)
             tempdff<-healthcareoutcome[healthcareoutcome$State==st,]
             tempdff 

              }

When i copy and paste of the R prompt of the R studio ,i get an error :

    Error: could not find function "testfunc15"
     > {
      + 
      + st<-state
      + out<-outcome 
      + print(st)
      + tempdff<-healthcareoutcome[healthcareoutcome$State==st,]
      + tempdff 
       + 
       + }
        Error: object 'state' not found

when i try to source it :source("testfunc15.R") then i get this error :

      Error in eval(expr, envir, enclos) : could not find function"testfunc15"

I am saving the file in the same getwd() as other functions ,other functions are working fine. Where am i going wrong ? I couldn't find an answer on stackoverflow though there were many questions with the same description. Please help

Upvotes: 2

Views: 10316

Answers (1)

Amandine FAURILLOU
Amandine FAURILLOU

Reputation: 612

The first line of your code is telling R to store the result of testfunc15(state, outcome) in a. It is not defining the function.

Also your function as written here doesn't exist. It should be, as mentionned by Dason, either :

testfunc15 = function (state, outcome) or testfunc15 <- function (state, outcome)

And the end could be return(tempdiff) or tempdiff

Upvotes: 2

Related Questions