Re: [R] Execution of larger blocks of pasted code often fails?

2013-05-29 Thread peter dalgaard

On May 28, 2013, at 19:26 , Mark Breman wrote:

 Thanks everyone for the suggestions.
 
 If the problem is caused by a restriction in one of the (software)
 components i'm using (OS, terminal etc), should the remaining of the pasted
 code simply be missing after the point where the error occurs? As can be
 seen from my example above the entire block of code is pasted and is
 executed by the R command line, although with errors from the point where
 the first error occured.

Looks like it is dropping characters when its input buffer runs full. That's 
pretty typical behavior for terminals (real and emulated). 

 
 Can it be that the paste mechanism i'm using (from GEdit to GNOME terminal
 on Ubuntu Linux) is adding control characters between pasting multiple
 blocks of code and these (invisible) characters are causing the problem?

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
R-help@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.


Re: [R] Execution of larger blocks of pasted code often fails?

2013-05-28 Thread Pascal Oettli

Hello,

Yes, I do. I just copy and paste smallest blocks, easiest to debug.

Regards,
Pascal


On 28/05/2013 15:54, Mark Breman wrote:

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!

Here is the output of my sessionInfo():


sessionInfo()

R version 2.15.3 (2013-03-01)
Platform: i486-pc-linux-gnu (32-bit)

locale:
  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
LC_TIME=nl_NL.UTF-8LC_COLLATE=en_US.UTF-8
LC_MONETARY=nl_NL.UTF-8
  [6] LC_MESSAGES=en_US.UTF-8LC_PAPER=C LC_NAME=C
LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=nl_NL.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
  [1] DEoptim_2.2-1  IBrokers_0.9-10stringr_0.6.2
timeDate_2160.97   PerformanceAnalytics_1.1.0
  [6] tradesys_0.1   RUnit_0.4.26   quantmod_0.4-0
   TTR_0.22-0 xts_0.9-3
[11] zoo_1.7-9  Defaults_1.1-1

loaded via a namespace (and not attached):
[1] grid_2.15.3 lattice_0.20-15 tcltk_2.15.3tools_2.15.3


Is there anyone who experiences the same problem?

Kind regards,

-Mark-

[[alternative HTML version deleted]]

__
R-help@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.



__
R-help@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.


Re: [R] Execution of larger blocks of pasted code often fails?

2013-05-28 Thread Barry Rowlingson
On Tue, May 28, 2013 at 7:54 AM, Mark Breman breman.m...@gmail.com wrote:
 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.

 This reminds me of the Tommy Cooper joke (I can't do the voice,
especially over email):

Man: Doctor, it hurts when I do this [waves arm about]
Doc: Well don't do that then.

 Cutting and pasting code - especially large blocks of code - is a
poor way to work with R. Make your code re-usable by putting it in
functions with sensible arguments and meaningful return values. Debug
your functions with little test data sets, or go the whole hog and use
package:testthat for writing test suites. Organise your functions into
packages and use package:devtools to make packages REALLY REALLY easy.
 Easier than having a big text file with all the R code you've ever
written in, and then pasting chunks of into R every time. Or pasting
it back into your big text file and then changing a little bit of it
so you now have two very similar chunks of R code with the same bug
now in two positions

 Take a day to read up on how to effectively work with R with
functions and packages, then revisit your work and see how that can
apply to you. You'll get that day back within a couple of weeks.

B

__
R-help@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.


Re: [R] Execution of larger blocks of pasted code often fails?

2013-05-28 Thread Enrico Schumann
On Tue, 28 May 2013, Mark Breman breman.m...@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

__
R-help@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.


Re: [R] Execution of larger blocks of pasted code often fails?

2013-05-28 Thread Enrico Schumann
On Tue, 28 May 2013, Enrico Schumann e...@enricoschumann.net writes:

 On Tue, 28 May 2013, Mark Breman breman.m...@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

I forgot to mention that this is with R 2.15.3 with x86_64-pc-linux-gnu
(64-bit), and it worked both in Emacs/ESS and when pasting to R running
in a GNOME Terminal.


 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

__
R-help@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.


Re: [R] Execution of larger blocks of pasted code often fails?

2013-05-28 Thread Jim Lemon

On 05/28/2013 04:54 PM, Mark Breman wrote:

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


Hi Mark,
I have encountered this problem, and it may be due to the following:

Command lines entered at the console are limited to about 4095 bytes 
(not characters).


From An Introduction to R, included in the distribution.

Jim

__
R-help@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.


Re: [R] Execution of larger blocks of pasted code often fails?

2013-05-28 Thread Spencer Graves
On 5/28/2013 2:44 AM, Jim Lemon wrote:
 On 05/28/2013 04:54 PM, Mark Breman wrote:
 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.
 ...

 Hi Mark,
 I have encountered this problem, and it may be due to the following:

 Command lines entered at the console are limited to about 4095 bytes 
 (not characters).

 From An Introduction to R, included in the distribution.


   From within RGui, the File option (upper left menu) offers, 
Source R Code, New Script, Open Script, ... .  I selected Open 
Script, then pasted your sample section into that window. Then I 
highlighted the first three lines and selected Edit - Run line or 
selection   Ctrl+R.  That caused the selected lines to be run without 
the paste step.


   Another options is to use ESS (Emacs Speaks Statistics, 
http://ess.r-project.org http://ess.r-project.org/). This has several 
advantages including an editor that interprets a file opened with a .R 
extension as R code and adjusts its display to help provide context 
sensitive indents -- to make it easier to see when you have failed to 
close a parentheses, coloring comment differently etc.  If you use 
Linux, you may already use Emacs.  If so, you only need to learn ESS.  
There's a separate email list for that.


   Hope this helps.
   Spencer


 Jim

 __
 R-help@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.


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Execution of larger blocks of pasted code often fails?

2013-05-28 Thread Prof Brian Ripley

On 28/05/2013 10:44, Jim Lemon wrote:

On 05/28/2013 04:54 PM, Mark Breman wrote:

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


Hi Mark,
I have encountered this problem, and it may be due to the following:

Command lines entered at the console are limited to about 4095 bytes
(not characters).


It is not.  That is a limit on line length.

It is a limitation of cut-and-paste.  That has limits depending on

- the OS
- how it is done (e.g. X11, GNOME, OS X) ... most OSes have multiple 
mechanisms, including Linux (which this was).

- where it is pasted from
- where it is pasted to.

We were told this was Linux: the most likely limitation is the terminal 
into which this was pasted.



 From An Introduction to R, included in the distribution.


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@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.


Re: [R] Execution of larger blocks of pasted code often fails?

2013-05-28 Thread Mark Breman
Thanks everyone for the suggestions.

If the problem is caused by a restriction in one of the (software)
components i'm using (OS, terminal etc), should the remaining of the pasted
code simply be missing after the point where the error occurs? As can be
seen from my example above the entire block of code is pasted and is
executed by the R command line, although with errors from the point where
the first error occured.

Can it be that the paste mechanism i'm using (from GEdit to GNOME terminal
on Ubuntu Linux) is adding control characters between pasting multiple
blocks of code and these (invisible) characters are causing the problem?

Kind regards,

-Mark-


2013/5/28 Prof Brian Ripley rip...@stats.ox.ac.uk

 On 28/05/2013 10:44, Jim Lemon wrote:

 On 05/28/2013 04:54 PM, Mark Breman wrote:

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


 Hi Mark,
 I have encountered this problem, and it may be due to the following:

 Command lines entered at the console are limited to about 4095 bytes
 (not characters).


 It is not.  That is a limit on line length.

 It is a limitation of cut-and-paste.  That has limits depending on

 - the OS
 - how it is done (e.g. X11, GNOME, OS X) ... most OSes have multiple
 mechanisms, including Linux (which this was).
 - where it is pasted from
 - where it is pasted to.

 We were told this was Linux: the most likely limitation is the terminal
 into which this was pasted.


   From An Introduction to R, included in the distribution.


 --
 Brian D. Ripley,  rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  
 http://www.stats.ox.ac.uk/~**ripley/http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595


[[alternative HTML version deleted]]

__
R-help@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.