See ?source
Uwe Ligges
On 14.12.2013 12:22, ???? wrote:> there is a file which contain such lines:
>
> test <-function(x,f){
> n<- length(x);
> sum(f*(x[1:(n-1)]+x[2:n])/2)/sum(f) -> result;
> return(result);
> }
>
> i can read it into terminal , cat test.R
> how can i do it in R?
>
>> readLines("c:/test.R",n=-1)
> [1] "test <-function(x,f){" "
n<- length(x);"
> [3] " sum(f*(x[1:(n-1)]+x[2:n])/2)/sum(f) -> result;" "
return(result);"
> [5] " }"
>> paste(readLines("c:/test.R",n=-1),collapse="")
> [1] "test <-function(x,f){ n<- length(x);
sum(f*(x[1:(n-1)]+x[2:n])/2)/sum(f) -> result; return(result); }"
>>
>
> is there better way to do ?can i get better format ?
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>