r - Store function definition as a character object -


take following example function

temp_fn <- function(){      print("hello world")  } 

i know typing function name without parenthesis return function definition, is:

> temp_fn function(){      print("hello world")  } 

however, can't figure out how store printed out character object. example

> store_temp_fn <- as.character(temp_fn) error in as.character(temp_fn) :    cannot coerce type 'closure' vector of type 'character' 

you can use capture.output() in combination function name this:

temp_fn <- function(){      print("hello world")  }  temp_fn_string <- cat(paste(capture.output(temp_fn), collapse = "\n"))  > temp_fn_string function(){      print("hello world")  }> 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -