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

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -