Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.SOC.4.64.1312131507090.1492@solcom.hrz.uni-giessen.de>
Date: 2013-12-13T14:16:30Z
From: Gerrit Eichner
Subject: how can i write the function into a file c:/mytest.R withcatfunction?
In-Reply-To: <tencent_3A82DB05585DDBD410796665@qq.com>

Hello, ????????!

> mytest<-function(x,f){
>        sum(x*f)/sum(f)
>        }
>    cat(mytest,file="c:/mytest.R")
>    Error in cat(list(...), file, sep, fill, labels, append) :
>    argument 1 (type 'closure') cannot be handled by 'cat'
>
> how can i write the mytest function into a file c:/mytest.R with cat function?

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