Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
117 views
in Technique[技术] by (71.8m points)

r - Access defined variable of function in another function

I am developing a Plumber Rest API where i have two function simplequery and GetData. So i want access or reuse variable (studies) in function GetData from function simplequery where I have used in function simplequery iswith function with parent.frame

for example :-

function simplequery

simplequery<- function{
    with(parent.frame(),{
       studies <- get_studies(study_id = query) 
  
       associations <- get_associations(study_id = query)
  
       paste("Studies: ", n(studies), ",Associations: ", n(associations))
    })
}

Function GetData

GetData <- function(query=""){
  
  simplequery()
  # Get the data of Studies
  study_table <- studies@studies
  
  # Get the data of publication
  publications_table <- studies@publications
  
  # Get the data of genotyping_techs_table
  genotyping_techs_table <- studies@genotyping_techs
  
  # Get the data of platforms_table
  platforms_table <- studies@platforms
  
  list(study_table, publications_table, genotyping_techs_table, platforms_table)
}

After running the api I get the result from function GetData but unable to get the result from function simplequery getting error

"Error in eval(substitute(expr), data, enclos = parent.frame()): object 'input' not found "

i don't know where the problem is

Please Help!

Thank you in Advance

question from:https://stackoverflow.com/questions/66050366/access-defined-variable-of-function-in-another-function

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...