Skip to content
Back to formatted view

Raw Message

Message-ID: <52AC47E6.7010205@statistik.tu-dortmund.de>
Date: 2013-12-14T11:58:30Z
From: Uwe Ligges
Subject: how to read file into terminal?
In-Reply-To: <tencent_00B1E7AC4371BF9A7EECD3A7@qq.com>

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.
>