Skip to content

how can i write the function into a file c:/mytest.R with cat function?

3 messages · 水静流深, Gerrit Eichner, William Dunlap

#
Hello, ????????!
Maybe by replacing cat(), e.g., by the use of sink():

sink( "c:/mytest.R")
mytest
sink()


You may want to look at ?dput and ?dget.


However, I doubt that that produces what you really want because only the 
body of your function mytest() will be stored in the file, but not the 
assignment that created it. Maybe you should store your R-code, i.e., the 
assignment in a text file (e.g., using R's editor) to -- later again -- 
use source() to read that file in and have it executed? See ?source.

  Hth  --  Gerrit
#
If you need to use cat() (why?) try using deparse() or format() on the function
   cat("mytest <- ", deparse(mytest), sep="\n", file=file)
but dump() is easier
   dump("mytest",file=file)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com