[R] Execution of larger blocks of pasted code often fails?
Enrico Schumann
es at enricoschumann.net
Tue May 28 11:33:53 CEST 2013
On Tue, 28 May 2013, Mark Breman <breman.mark at gmail.com> writes:
> Hello List,
>
> When i paste a large block of R code from an editor to the R command line
> the execution of the code will often fail at some point because it is not
> pasted as it was copied.
>
> ===============================================================
> Example:
>
> I copied the following block of code (as part of a larger block):
>
> ....
> s$Price <- quote(prices(St, uc=Adjusted, ent=c(Adjusted[-1], NA),
> xit=c(Adjusted[-1], NA)))
> s$PnL <- quote(pnl(Price, St))
> s$PPnL <- quote(ppnl(Price, St))
> s$RoR <- quote(ror(Price, St, delta=1/Price))
> t = na.omit(trades(rownames(s), s$Price, s$St))
> ....
>
> and when i paste this to the R command-line the following happens:
>
> ....
>> s$Price <- quote(prices(St, uc=Adjusted, ent=c(Adjusted[-1], NA),
> xit=c(Adjusted[-1], NA)))
>> s$PnL <- quote(pnl(Price,
> +
> + s$RoR <- quote(ror(Pr
> + t = na.omit(trade
> Error: unexpected symbol in:
> "s$RoR <- quote(ror(Pr
> t"
> ....
> =================================================================
>
> As you can see from the example it looks like the code was not pasted
> correctly.
> If i execute the same block of code with the source() command it runs just
> fine!
>
[...]
Just for the record, I can copy and paste your code -- and get errors of
the type
Error in na.omit(trades(rownames(s), s$Price, s$St)) :
could not find function "trades"
But as others have already pointed out, it is better to '?source' code,
or to use an editor that can push code chunks directly to R.
--
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net
More information about the R-help
mailing list