Re: [Rd] Does anyone use Sweave (RweaveLatex) option expand=FALSE?

2010-08-30 Thread Duncan Murdoch

On 19/08/2010 5:25 PM, Duncan Murdoch wrote:

On 19/08/2010 5:07 PM, Kevin Coombes wrote:
 I use it, frequently. The idea for it goes back to some of Knuth's 
 original literate programming ideas for developing weave and tangle when 
 he was writing TeX (the program).  I want to be able to document the 
 pieces of some complex algorithm without having to see all of the gory 
 details.  For instance, I have code that looks like the following.  
 (Note that this is typed on the fly rather than copied from actual 
 source, so there may be typos.)


Okay, thanks.  I'll keep it in.  So now I have a question:  suppose
you have an error (syntax error at this point, maybe some other kinds of 
error in the future) in the getInfoAboutThisSample chunk, but that 
chunk wasn't eval'd, mainloop was eval'd.  So the error is going to be 
reported as occurring in chunk mainloop, but with a line number from 
somewhere else in the file.  Is that a problem?
  


I was out of town for a week, but I'm back now, and have just committed 
these changes.  Hopefully the reports of syntax errors will be a little 
more helpful now.  I don't think I'll have time to make the reports of 
execution time errors better before the 2.12.0 release.


Duncan Murdoch


Duncan Murdoch


 
 mainloop,keep.source=TRUE,expand=FALSE=

 for (i in 1:nSamples) {
 getInfoAboutThisSample
  for (j in 1:nChromosomes) {
 getChromosomeDataForCurrentSample
 normalizeChromosomeData
 findSegments
 computeSignificance
 writeResults
  }
 }
 @
 
 Each of the chunks is itself a fairly long piece of code defined and 
 documented somewhere else.  (Some of them may themselves be written in 
 the same form to reduce the final size of a chunk to something a human 
 has a chance of understanding. That's the difference between weave and 
 tangle in the original implementation.)   By blocking expansion, I can 
 focus on the main steps without having them lost in pages and pages of code.
 
 So I vote strongly for retaining expand=FALSE.
 
 Best,

 Kevin
 
 Duncan Murdoch wrote:

 On 19/08/2010 4:29 PM, Claudia Beleites wrote:
 I never used it.

 I got curious, though. What would be a situation that benefits of 
 this option?
   
 When I put it in, I thought it would be for people who were writing 
 about Sweave.


 Duncan Murdoch

 Maybe a use case could be found by brute force (grep all .Rnw files 
 on CRAN for the option?


 Claudia


 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel




__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Does anyone use Sweave (RweaveLatex) option expand=FALSE?

2010-08-20 Thread Terry Therneau
Duncan,
  I use noweb for my R source code on the more complex projects (see the
coxme package).  I currently have my own noweb.R functions to do the
work, but the overlap is so great with Sweave that I have hopes that
they will one day merge.  

A note on abc recursion: for documentation this is very well
designed; it's better than a macro or a function would be.  And of
course, documentation of code is what the system was designed for.

And a general query: I currently have the .Rnw source files in the
inst/noweb directory.  Do people have a better suggestion?  Remember
these .Rnw files are the source of my .R files and of document
explaining the code, not the source of vignettes or manual pages.

Terry Therneau

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Does anyone use Sweave (RweaveLatex) option expand=FALSE?

2010-08-19 Thread Marc Schwartz
On Aug 19, 2010, at 2:07 PM, Duncan Murdoch wrote:

 I am trying to improve the error reporting in Sweave documents, so that if 
 you have a syntax error in a code chunk, it will tell you which line of your 
 input file contained the error.
 
 For example, currently you get this:
 
 Error:  chunk 1 (label=named)
 Error in parse(text = chunk) : unexpected symbol in x - foo bar
 Execution halted
 
 and I'd like errors to be more like this:
 
 Error:  chunk 1 (label=named)
 Error in parse(text = chunk, srcfile = srcfile) :
 test.Rnw:9:10: unexpected symbol
 9: x - foo bar
   ^
 Execution halted
 
 It turns out that this requires changes that make the expand=FALSE option 
 quite hard to implement.  Is anyone using it?  For those who don't know it, 
 expand=FALSE means that a code chunk like
 
 echo=TRUE, keep.source=TRUE,expand=FALSE=
 z - 3
 named
 @
 
 will be displayed as
 
  z - 3
  named
 
 rather than expanding the named chunk.  I'd like to drop the option, so that 
 the default behaviour (which has always been equivalent to expand = TRUE) 
 would be the only behaviour.
 
 Duncan Murdoch


I don't. So 1 go ahead and drop it vote...

You may want to post this to R-Help though Duncan, as I suspect there may be 
more Sweave users there than here...

Thanks and regards,

Marc Schwartz

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Does anyone use Sweave (RweaveLatex) option expand=FALSE?

2010-08-19 Thread Kasper Daniel Hansen
I have read a significant number of vignettes from Bioconductor
packages and I have never seen it used.

Kasper

On Thu, Aug 19, 2010 at 3:17 PM, Marc Schwartz marc_schwa...@me.com wrote:
 On Aug 19, 2010, at 2:07 PM, Duncan Murdoch wrote:

 I am trying to improve the error reporting in Sweave documents, so that if 
 you have a syntax error in a code chunk, it will tell you which line of your 
 input file contained the error.

 For example, currently you get this:

 Error:  chunk 1 (label=named)
 Error in parse(text = chunk) : unexpected symbol in x - foo bar
 Execution halted

 and I'd like errors to be more like this:

 Error:  chunk 1 (label=named)
 Error in parse(text = chunk, srcfile = srcfile) :
 test.Rnw:9:10: unexpected symbol
 9: x - foo bar
           ^
 Execution halted

 It turns out that this requires changes that make the expand=FALSE option 
 quite hard to implement.  Is anyone using it?  For those who don't know it, 
 expand=FALSE means that a code chunk like

 echo=TRUE, keep.source=TRUE,expand=FALSE=
 z - 3
 named
 @

 will be displayed as

  z - 3
  named

 rather than expanding the named chunk.  I'd like to drop the option, so that 
 the default behaviour (which has always been equivalent to expand = TRUE) 
 would be the only behaviour.

 Duncan Murdoch


 I don't. So 1 go ahead and drop it vote...

 You may want to post this to R-Help though Duncan, as I suspect there may be 
 more Sweave users there than here...

 Thanks and regards,

 Marc Schwartz

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Does anyone use Sweave (RweaveLatex) option expand=FALSE?

2010-08-19 Thread Duncan Murdoch

On 19/08/2010 3:17 PM, Marc Schwartz wrote:

On Aug 19, 2010, at 2:07 PM, Duncan Murdoch wrote:

 I am trying to improve the error reporting in Sweave documents, so that if 
you have a syntax error in a code chunk, it will tell you which line of your input 
file contained the error.
 
 For example, currently you get this:
 
 Error:  chunk 1 (label=named)

 Error in parse(text = chunk) : unexpected symbol in x - foo bar
 Execution halted
 
 and I'd like errors to be more like this:
 
 Error:  chunk 1 (label=named)

 Error in parse(text = chunk, srcfile = srcfile) :
 test.Rnw:9:10: unexpected symbol
 9: x - foo bar
   ^
 Execution halted
 
 It turns out that this requires changes that make the expand=FALSE option quite hard to implement.  Is anyone using it?  For those who don't know it, expand=FALSE means that a code chunk like
 
 echo=TRUE, keep.source=TRUE,expand=FALSE=

 z - 3
 named
 @
 
 will be displayed as
 
  z - 3

  named
 
 rather than expanding the named chunk.  I'd like to drop the option, so that the default behaviour (which has always been equivalent to expand = TRUE) would be the only behaviour.
 
 Duncan Murdoch



I don't. So 1 go ahead and drop it vote...

You may want to post this to R-Help though Duncan, as I suspect there may be 
more Sweave users there than here...
  


I probably will before I go ahead with this, but I may as well start on 
this group.


Duncan

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Does anyone use Sweave (RweaveLatex) option expand=FALSE?

2010-08-19 Thread Claudia Beleites

I never used it.

I got curious, though. What would be a situation that benefits of this option?

Maybe a use case could be found by brute force (grep all .Rnw files on CRAN 
for the option?


Claudia

--
Claudia Beleites
Dipartimento dei Materiali e delle Risorse Naturali
Università degli Studi di Trieste
Via Alfonso Valerio 6/a
I-34127 Trieste

phone: +39 0 40 5 58-37 68
email: cbelei...@units.it

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Does anyone use Sweave (RweaveLatex) option expand=FALSE?

2010-08-19 Thread Duncan Murdoch

On 19/08/2010 4:29 PM, Claudia Beleites wrote:

I never used it.

I got curious, though. What would be a situation that benefits of this option?
  


When I put it in, I thought it would be for people who were writing 
about Sweave.


Duncan Murdoch

Maybe a use case could be found by brute force (grep all .Rnw files on CRAN 
for the option?


Claudia




__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Does anyone use Sweave (RweaveLatex) option expand=FALSE?

2010-08-19 Thread Kevin Coombes
I use it, frequently. The idea for it goes back to some of Knuth's 
original literate programming ideas for developing weave and tangle when 
he was writing TeX (the program).  I want to be able to document the 
pieces of some complex algorithm without having to see all of the gory 
details.  For instance, I have code that looks like the following.  
(Note that this is typed on the fly rather than copied from actual 
source, so there may be typos.)


mainloop,keep.source=TRUE,expand=FALSE=
for (i in 1:nSamples) {
getInfoAboutThisSample
for (j in 1:nChromosomes) {
getChromosomeDataForCurrentSample
normalizeChromosomeData
findSegments
computeSignificance
writeResults
}
}
@

Each of the chunks is itself a fairly long piece of code defined and 
documented somewhere else.  (Some of them may themselves be written in 
the same form to reduce the final size of a chunk to something a human 
has a chance of understanding. That's the difference between weave and 
tangle in the original implementation.)   By blocking expansion, I can 
focus on the main steps without having them lost in pages and pages of code.


So I vote strongly for retaining expand=FALSE.

Best,
   Kevin

Duncan Murdoch wrote:

On 19/08/2010 4:29 PM, Claudia Beleites wrote:

I never used it.

I got curious, though. What would be a situation that benefits of 
this option?
  


When I put it in, I thought it would be for people who were writing 
about Sweave.


Duncan Murdoch

Maybe a use case could be found by brute force (grep all .Rnw files 
on CRAN for the option?


Claudia




__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Does anyone use Sweave (RweaveLatex) option expand=FALSE?

2010-08-19 Thread Duncan Murdoch

On 19/08/2010 5:07 PM, Kevin Coombes wrote:
I use it, frequently. The idea for it goes back to some of Knuth's 
original literate programming ideas for developing weave and tangle when 
he was writing TeX (the program).  I want to be able to document the 
pieces of some complex algorithm without having to see all of the gory 
details.  For instance, I have code that looks like the following.  
(Note that this is typed on the fly rather than copied from actual 
source, so there may be typos.)


Okay, thanks.  I'll keep it in.  So now I have a question:  suppose
you have an error (syntax error at this point, maybe some other kinds of 
error in the future) in the getInfoAboutThisSample chunk, but that 
chunk wasn't eval'd, mainloop was eval'd.  So the error is going to be 
reported as occurring in chunk mainloop, but with a line number from 
somewhere else in the file.  Is that a problem?


Duncan Murdoch




mainloop,keep.source=TRUE,expand=FALSE=
for (i in 1:nSamples) {
getInfoAboutThisSample
 for (j in 1:nChromosomes) {
getChromosomeDataForCurrentSample
normalizeChromosomeData
findSegments
computeSignificance
writeResults
 }
}
@

Each of the chunks is itself a fairly long piece of code defined and 
documented somewhere else.  (Some of them may themselves be written in 
the same form to reduce the final size of a chunk to something a human 
has a chance of understanding. That's the difference between weave and 
tangle in the original implementation.)   By blocking expansion, I can 
focus on the main steps without having them lost in pages and pages of code.


So I vote strongly for retaining expand=FALSE.

Best,
Kevin

Duncan Murdoch wrote:

On 19/08/2010 4:29 PM, Claudia Beleites wrote:

I never used it.

I got curious, though. What would be a situation that benefits of 
this option?
  
When I put it in, I thought it would be for people who were writing 
about Sweave.


Duncan Murdoch

Maybe a use case could be found by brute force (grep all .Rnw files 
on CRAN for the option?


Claudia



__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Does anyone use Sweave (RweaveLatex) option expand=FALSE?

2010-08-19 Thread Kevin Coombes
I picked the example from segmenting chromosomes for a reason.  I have a 
fair chunk of code that deals with not quite exceeding the amount of RAM 
available in the machine sitting on my desktop.  If I use functions, 
then the pass-by-value semantics of R will push me beyond the limits at 
some points.  (This is an empirical statement, not a theoretical one.  I 
was bitten by it several times while trying to analyze a couple of these 
datasets. And, yes, I know I can get around this by buying a bigger and 
better machine; it's on order...)  The real point is that using 
functions can be detrimental to the efficiency of the program, in ways 
that have real world consequences.


I haven't thought about doing the same thing with expressions. 
Expressions don't have quite the same semantics as chunks, and you'd 
have to make sure the evaluation was delayed so that you cold use the 
current values of things that were computed in the meantime and I 
already know how to do this with chunks without having to think so hard.


Using expressons would, however, help with the one difficulty that I 
have with reusing chunks (independent of whether or not I use 
'expand=FALSE').  I usually work inside emacs, using the 
emacs-speaks-statistics (ESS) package. ESS doesn't know how to evaluate 
the chunk call inside another chunk. so if I want to step through 
the code during development, I have to jump around myself to locate the 
source chunks.  With expressions that wouldn't matter.


As I ramble on about this, it occurs to me that the underlying issue is 
that chunks are not first class objects either in the LaTeX world or 
in the R world part of Sweave.  If there were a way to promote them to 
first class objects somehow, then it might make my use of ESS easier 
while simultaneously making it easier for Duncan to figure out how to 
report the correct line numbers.  But I only have an extremely vague 
idea of how one might start to do that...


   Kevin

Matt Shotwell wrote:

On Thu, 2010-08-19 at 17:07 -0400, Kevin Coombes wrote:
  
I use it, frequently. The idea for it goes back to some of Knuth's 
original literate programming ideas for developing weave and tangle when 
he was writing TeX (the program).  I want to be able to document the 
pieces of some complex algorithm without having to see all of the gory 
details.  For instance, I have code that looks like the following.  
(Note that this is typed on the fly rather than copied from actual 
source, so there may be typos.)


mainloop,keep.source=TRUE,expand=FALSE=
for (i in 1:nSamples) {
getInfoAboutThisSample
 for (j in 1:nChromosomes) {
getChromosomeDataForCurrentSample
normalizeChromosomeData
findSegments
computeSignificance
writeResults
 }
}
@

Each of the chunks is itself a fairly long piece of code defined and 
documented somewhere else.  (Some of them may themselves be written in 
the same form to reduce the final size of a chunk to something a human 
has a chance of understanding. That's the difference between weave and 
tangle in the original implementation.)   By blocking expansion, I can 
focus on the main steps without having them lost in pages and pages of code.





Couldn't you achieve the same amount of abstraction using function
calls, rather than embedded code chunks? The reader can then see real
code, rather than non-code, or meta-code, or whatever. Alternatively,
represent the code chunks as R expressions, then evaluate the
expressions at the appropriate points.

-Matt

  

So I vote strongly for retaining expand=FALSE.

Best,
Kevin

Duncan Murdoch wrote:


On 19/08/2010 4:29 PM, Claudia Beleites wrote:
  

I never used it.

I got curious, though. What would be a situation that benefits of 
this option?
  

When I put it in, I thought it would be for people who were writing 
about Sweave.


Duncan Murdoch

  
Maybe a use case could be found by brute force (grep all .Rnw files 
on CRAN for the option?


Claudia




__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
  

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel






__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Does anyone use Sweave (RweaveLatex) option expand=FALSE?

2010-08-19 Thread Gabor Grothendieck
On Thu, Aug 19, 2010 at 6:21 PM, Kevin Coombes
kevin.r.coom...@gmail.com wrote:
 I picked the example from segmenting chromosomes for a reason.  I have a
 fair chunk of code that deals with not quite exceeding the amount of RAM
 available in the machine sitting on my desktop.  If I use functions, then
 the pass-by-value semantics of R will push me beyond the limits at some
 points.  (This is an empirical statement, not a theoretical one.  I was
 bitten by it several times while trying to analyze a couple of these
 datasets. And, yes, I know I can get around this by buying a bigger and
 better machine; it's on order...)  The real point is that using functions
 can be detrimental to the efficiency of the program, in ways that have real
 world consequences.

 I haven't thought about doing the same thing with expressions. Expressions
 don't have quite the same semantics as chunks, and you'd have to make sure
 the evaluation was delayed so that you cold use the current values of things
 that were computed in the meantime and I already know how to do this
 with chunks without having to think so hard.

 Using expressons would, however, help with the one difficulty that I have
 with reusing chunks (independent of whether or not I use
 'expand=FALSE').  I usually work inside emacs, using the
 emacs-speaks-statistics (ESS) package. ESS doesn't know how to evaluate the
 chunk call inside another chunk. so if I want to step through the code
 during development, I have to jump around myself to locate the source
 chunks.  With expressions that wouldn't matter.

 As I ramble on about this, it occurs to me that the underlying issue is that
 chunks are not first class objects either in the LaTeX world or in the R
 world part of Sweave.  If there were a way to promote them to first class
 objects somehow, then it might make my use of ESS easier while
 simultaneously making it easier for Duncan to figure out how to report the
 correct line numbers.  But I only have an extremely vague idea of how one
 might start to do that...


You could try a macro instead and see how it performs.  There is an
article by Thomas Lumley in R News 2003-1 and an implementation in the
gtools package.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Does anyone use Sweave (RweaveLatex) option expand=FALSE?

2010-08-19 Thread Charles C. Berry

On Thu, 19 Aug 2010, Kevin Coombes wrote:

I picked the example from segmenting chromosomes for a reason.  I have a fair 
chunk of code that deals with not quite exceeding the amount of RAM available 
in the machine sitting on my desktop.  If I use functions, then the 
pass-by-value semantics of R will push me beyond the limits at some points. 
(This is an empirical statement, not a theoretical one.  I was bitten by it 
several times while trying to analyze a couple of these datasets. And, yes, I 
know I can get around this by buying a bigger and better machine; it's on 
order...)  The real point is that using functions can be detrimental to the 
efficiency of the program, in ways that have real world consequences.


I haven't thought about doing the same thing with expressions. Expressions 
don't have quite the same semantics as chunks, and you'd have to make sure 
the evaluation was delayed so that you cold use the current values of things 
that were computed in the meantime and I already know how to do this with 
chunks without having to think so hard.


Using expressons would, however, help with the one difficulty that I have 
with reusing chunks (independent of whether or not I use 'expand=FALSE'). 
I usually work inside emacs, using the emacs-speaks-statistics (ESS) package. 
ESS doesn't know how to evaluate the chunk call inside another chunk. so 
if I want to step through the code during development, I have to jump around 
myself to locate the source chunks.  With expressions that wouldn't matter.




emacs org-mode might help.

You can define a chunk, ch1 (say), then place it in a subsequent 
chunk, ch2 (say), inside an eval() and refer to ch2 inside an 
eval() inside another chunk, ch3, and so on. The only trick is to 
write the chunk so that the chunk it refers to is on its own line, like 
this:


#+source: ch3
#+begin_src R :session :noweb yes
eval(
ch2
)
z - mean(y)+1
#+end_src

as the noweb expansion will repeat any other text on the line with the 
named chunk for each line of code in the referenced chunk.


You can define a library of chunks separately, which might help you if you 
reuse them in different places.


You can use ess-mode to edit the chunks and execute them with the usual 
ess-eval-* commands, or run them in org-mode with the results optionally 
returned to the edit buffer, but outside the code block.


If you want to debug a bunch of nested chunks and 'step through the code 
during development', you can tangle the chunk you wish to execute to 
produce a *.R file. The nested chunks are expanded into R. Open that *.R 
file and debug away.


With a recent emacs, I think this gets you going:

C-h i m Org Mode RET C-s source RET RET

or Google 'org-babel R' or some such or just go look here:


http://blogisticreflections.wordpress.com/

As I ramble on about this, it occurs to me that the underlying issue is that 
chunks are not first class objects either in the LaTeX world or in the R 
world part of Sweave.  If there were a way to promote them to first class 
objects somehow, then it might make my use of ESS easier while simultaneously 
making it easier for Duncan to figure out how to report the correct line 
numbers.  But I only have an extremely vague idea of how one might start to 
do that...


org-mode might be the path of least resistance.

FWIW, the code chunks are objects processed by emacs-lisp before they are 
handed off to R, so there might be a slicker way to handle the nesting 
than dropping chunks inside eval()s in R blocks. If that interests you, 
there is a very active listserv for orgmode, where you might inqure.


HTH,

Chuck






  Kevin

Matt Shotwell wrote:

 On Thu, 2010-08-19 at 17:07 -0400, Kevin Coombes wrote:

  I use it, frequently. The idea for it goes back to some of Knuth's 
  original literate programming ideas for developing weave and tangle when 
  he was writing TeX (the program).  I want to be able to document the 
  pieces of some complex algorithm without having to see all of the gory 
  details.  For instance, I have code that looks like the following. 
  (Note that this is typed on the fly rather than copied from actual 
  source, so there may be typos.)
 
  mainloop,keep.source=TRUE,expand=FALSE=

  for (i in 1:nSamples) {
  getInfoAboutThisSample
  for (j in 1:nChromosomes) {
  getChromosomeDataForCurrentSample
  normalizeChromosomeData
  findSegments
  computeSignificance
  writeResults
   }
  }
  @
 
  Each of the chunks is itself a fairly long piece of code defined and 
  documented somewhere else.  (Some of them may themselves be written in 
  the same form to reduce the final size of a chunk to something a human 
  has a chance of understanding. That's the difference between weave and 
  tangle in the original implementation.)   By blocking expansion, I can 
  focus on the main steps without having them lost in pages and pages of 
  code.
 
 


 Couldn't you achieve the same amount of abstraction using function