Re: [R] R-code in html help pages: syntax highlighting

2009-03-17 Thread Romain Francois

Duncan Murdoch wrote:

On 16/03/2009 5:06 PM, Romain Francois wrote:

hadley wickham wrote:
It would be pretty easy to use the output from the R parser (which 
is never
wrong, is it?), and dump some markup out of it. For example the 
showTree
function in codetools dumps an R expression as Lisp, this is not 
too far

from generating html, or any other markup.

As this sounds like fun, I'll volunteer to do something about this. 
Another
advantage is that we can imagine to plug hyperlinks in  R code that 
lives in

html help pages.


This also sounds like a good idea for a google summer of code project
- that way you might be able to get a student to give you a hand as
well.

Hadley
  
That did cross my mind earlier this evening, it just seems a bit too 
easy to last all summer, but maybe I am missing something difficult. 
I will start to play with this over the next few days, and make up my 
mind.


It depends on your standards.  You said you want R to parse the code 
in the Rd file.  That's going to be hard, because Rd files contain 
something that is only R-like, as far as the parser is concerned. 
You'll need to convert it into R code before you can pass it to the R 
parser.


I would assume this would be outsourced to the experimental parse_Rd 
function


And then there's the question of scoping, which gets into the 
evaluator, not just the parser.  (The parser only recognizes mean as 
an identifier; it's the evaluator that decides whether it's the 
function in the base package or a local variable.)


That is an issue. I guess I will fall back on what the parser says and 
infer on the scoping. Within the lines below, mean would be different 
each time


mean( 1:10 )
lapply( 1:10, mean)
mean - (1+4) / 2
lapply( list( mean, median), function( f ) f( 1:10) )
{ mean - median; mean( 1:10 ) }

So if you've got high standards, it's probably quite hard.  On the 
other hand, if you're willing to accept the usual sort of errors that 
syntax highlighters make, it's not so bad, but not trivial.


There is probably some middle ground between the job an highlighter 
would do, and the way the R evaluator would think the expression 
eventually. Given that this is more a nice to have feature, I guess we 
can accept some errors. checkUsage is wrong sometimes, but it is still a 
good tool.




One of the problem I might run into is performance, if we want this 
to treat all Rd files, we are going to want something very efficient, 
and it might not be enough to build on top of codetools (which uses 
recursion at the R level) , but could make sense to provide a C level 
implementation.


Remember what Knuth said about premature optimization.  Write it first 
in R, and only optimize it if it's not fast enough.  


Deal

(I'd guess it'll be fast enough: Brian Ripley reported that all the R 
code he wrote for conversions in R-devel was faster than the Perl code 
it was replacing.)


That is good news




This could lead to interesting things as:
- syntax highlighting in sweave (or decumar)
- pretty printing in the console (using ansi characters)
- syntax highlighting in R help files, potentially with hyperlinks

I have requested creation of a project on r-forge. Anyone else want 
to play with this ?


I'll sign up once it's going.

Duncan Murdoch








--
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr

__
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] R-code in html help pages: syntax highlighting

2009-03-17 Thread Wacek Kusnierczyk
Romain Francois wrote:
 Duncan Murdoch wrote:

 That is an issue. I guess I will fall back on what the parser says and
 infer on the scoping. Within the lines below, mean would be different
 each time

 mean( 1:10 )
 lapply( 1:10, mean)
 mean - (1+4) / 2
 lapply( list( mean, median), function( f ) f( 1:10) )
 { mean - median; mean( 1:10 ) }

 So if you've got high standards, it's probably quite hard.  On the
 other hand, if you're willing to accept the usual sort of errors that
 syntax highlighters make, it's not so bad, but not trivial.


it would be good to know what you mean by 'errors'.  syntax highlighters
are, in principle, *syntax* highlighters.  in the example above, the
first and sixth occurrences of 'mean' are in the operator position, the
others are not -- would it be *syntactically* inappropriate to
color-code the former in one way, and the latter in another?  why should
a *syntax* highlighter care about what's the object referred to by
'mean' in this or other context?

otherwise, it would certainly be fun to have a semantic highlighter for r.

(..)



 (I'd guess it'll be fast enough: Brian Ripley reported that all the R
 code he wrote for conversions in R-devel was faster than the Perl
 code it was replacing.)

the 'benchmark' you are talking about is only as good as the perl
scripts were.  i have had a look at a couple of perl scripts in the r
sources, and it seemed like there was quite some space for improvement.


vQ

__
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] R-code in html help pages: syntax highlighting

2009-03-17 Thread Romain Francois

Wacek Kusnierczyk wrote:

Romain Francois wrote:
  

Duncan Murdoch wrote:

That is an issue. I guess I will fall back on what the parser says and
infer on the scoping. Within the lines below, mean would be different
each time

mean( 1:10 )
lapply( 1:10, mean)
mean - (1+4) / 2
lapply( list( mean, median), function( f ) f( 1:10) )
{ mean - median; mean( 1:10 ) }



So if you've got high standards, it's probably quite hard.  On the
other hand, if you're willing to accept the usual sort of errors that
syntax highlighters make, it's not so bad, but not trivial.
  


it would be good to know what you mean by 'errors'.  syntax highlighters
are, in principle, *syntax* highlighters.  in the example above, the
first and sixth occurrences of 'mean' are in the operator position, the
others are not -- would it be *syntactically* inappropriate to
color-code the former in one way, and the latter in another?  
It would certainly be useful to make a difference between the first one 
(call to the mean function from base) and the last one.


If we have sufficient evidence of where the function lives, it would be 
useful for the syntax highlighter to present this evidence.


I'd like to see function highlighted differently for:
- function in standard R packages
- function exported from the NAMESPACE of the package being highlighted
- function not exported from the NAMESPACE
- function which belongs to a package on which this one depends

It makes the job trivial if we just don't care and put all function 
calls to the same basket.


But because of scoping rules, and tricks, there are going to be errors.

f - function( ){
   assign( mean, median )
   mean( 1:10)
}

f - function( ){
   assign( paste(m, e, a, n, sep = ), median )
   mean( 1:10)
}

f - function( ){
   eval( parse( text = 'assign( paste(m, e, a, n, sep = ), 
median )') )

   mean( 1:10)
}

... and so on.



why should
a *syntax* highlighter care about what's the object referred to by
'mean' in this or other context?

otherwise, it would certainly be fun to have a semantic highlighter for r.

(..)

  


(I'd guess it'll be fast enough: Brian Ripley reported that all the R
code he wrote for conversions in R-devel was faster than the Perl
code it was replacing.)
  


the 'benchmark' you are talking about is only as good as the perl
scripts were.  i have had a look at a couple of perl scripts in the r
sources, and it seemed like there was quite some space for improvement.


vQ


  



--
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr

__
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] R-code in html help pages: syntax highlighting

2009-03-17 Thread Wacek Kusnierczyk
Romain Francois wrote:
 Wacek Kusnierczyk wrote:

  
 Duncan Murdoch wrote:


 So if you've got high standards, it's probably quite hard.  On the
 other hand, if you're willing to accept the usual sort of errors that
 syntax highlighters make, it's not so bad, but not trivial.
   

 it would be good to know what you mean by 'errors'.  syntax highlighters
 are, in principle, *syntax* highlighters.  in the example above, the
 first and sixth occurrences of 'mean' are in the operator position, the
 others are not -- would it be *syntactically* inappropriate to
 color-code the former in one way, and the latter in another?  
 It would certainly be useful to make a difference between the first
 one (call to the mean function from base) and the last one.

of course!  i was referring to duncan's prompt use of the term 'error'
in this context.

vQ

__
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] R-code in html help pages: syntax highlighting

2009-03-16 Thread Jose Quesada
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
 
Hi,

A follow up to my previous post. It'd be good to have syntax
highlighting in the html help pages. There is highlight
(http://www.andre-simon.de/) which seems to be open source. Since code
is delimited in the help file format, it should not be too difficult
to run a highlighting program (actually, vim and emacs do this too)
recursively and pretty-print all the R examples in the entire CRAN.
Including the highlighter with R, or whatever supplementary tools
people use to make R html help files could simplify things. I've never
written docs or released a package, so I may be understimating the
effort it'd take to get this working.

Using the r-help gmane archives also leads to plain code.
This is probably more trouble than it's worth, since there's no
metadata delimiting a block of code and it might be difficult... but
grepping through all R-help posts and coloring code would be really
nice too. Again, this lands straight into 'nice to have, but not
essential' territory.

If anyone wants to do this, feel free to.

Best,
- -J

- --
Jose Quesada, PhD.
Max Planck Institute,
Center for Adaptive Behavior and cognition,
Berlin
http://www.josequesada.name/   
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iQIVAwUBSb6RRGMobUVGH+HKAQI2RxAAijNIj7qlBogc9M6lhQ2Ah1Px29iU/uzS
45t5blwNSGVSbAbZF7N7rRcBdn8/c4W8n+oI62nnap0snwLMFW/ynikVNJuBY+XA
+yNaO5nIJo5SWu60WkcMinm/ysPZ4o4Jdxr1+lGfJ/ceVSTWPWVLb//GN8QElgwT
Vf0ZQUSqfWczzeVDSDtfMKGTJOz4y60eF5hounA/PkzyUd8RRo1WpEXzJHYsCTI+
RwBrYZ5Q30cpKLAJQNeiiv8GDtv7QvJl38uRAqBRK5Ec9CGC0brGZquX8UgHi1q1
1+NzHSt95E4Y0CKWPS48t+eO58MUE8v69gjLa9DdnhII4tCdAUURuP+AsaFm+hzP
a7OufMNnh/S8igDmqon0c9W6sJrkDo9DdrZPlu6MFjGQ5SbS6mSfvwSRKVd3RTCN
2/+uz0EwBygq1OKS+Z7Z+kx29UR8+bNXOGaPRlsr5CKcwVV9w3FBvEICuDaP75vj
l0d75+2R+CB/R/e2+dMMRCQY5MNWtYuuqoz3jNws59J+0z5K35usLoaKdB7Ez3D6
G2CCBKJSrugT0s8OkhX5pcTiU6NUIrq6q8h7JNEeuR0bniFClXlDrAs9iIdNb4PS
oFpqtNJWPLaicHRMnJdnxPCriHa0lmI3QVoGrf6UFtBAXuiOkFxcHUmTcQczyfOm
IGyGcgCko3o=
=djsT
-END PGP SIGNATURE-

__
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] R-code in html help pages: syntax highlighting

2009-03-16 Thread Romain Francois

Hi Jose,

highlight is fairly easy to use from command line. I have something like 
this when I use R from a console that supports color characters:


highlight - function( fun ){
 fun - match.fun( fun )
 tf - tempfile()
 dump( fun, tf )
 system( sprintf( highlight -A -S R %s, tf ) )
 unlink( tf )
}

R highlight( glm )

Replace -A with -f -H and you have html output ready for pasting 
into a blog or whatever.


See also ?file for how you might want to send the generated output to 
the clipboard, so that you only have Control + V to type on the web 
browser.


Romain

Jose Quesada wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
 
Hi,


A follow up to my previous post. It'd be good to have syntax
highlighting in the html help pages. There is highlight
(http://www.andre-simon.de/) which seems to be open source. Since code
is delimited in the help file format, it should not be too difficult
to run a highlighting program (actually, vim and emacs do this too)
recursively and pretty-print all the R examples in the entire CRAN.
Including the highlighter with R, or whatever supplementary tools
people use to make R html help files could simplify things. I've never
written docs or released a package, so I may be understimating the
effort it'd take to get this working.

Using the r-help gmane archives also leads to plain code.
This is probably more trouble than it's worth, since there's no
metadata delimiting a block of code and it might be difficult... but
grepping through all R-help posts and coloring code would be really
nice too. Again, this lands straight into 'nice to have, but not
essential' territory.

If anyone wants to do this, feel free to.

Best,
- -J

- --
Jose Quesada, PhD.
Max Planck Institute,
Center for Adaptive Behavior and cognition,
Berlin
http://www.josequesada.name/   
-BEGIN PGP SIGNATURE-

Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iQIVAwUBSb6RRGMobUVGH+HKAQI2RxAAijNIj7qlBogc9M6lhQ2Ah1Px29iU/uzS

45t5blwNSGVSbAbZF7N7rRcBdn8/c4W8n+oI62nnap0snwLMFW/ynikVNJuBY+XA
+yNaO5nIJo5SWu60WkcMinm/ysPZ4o4Jdxr1+lGfJ/ceVSTWPWVLb//GN8QElgwT
Vf0ZQUSqfWczzeVDSDtfMKGTJOz4y60eF5hounA/PkzyUd8RRo1WpEXzJHYsCTI+
RwBrYZ5Q30cpKLAJQNeiiv8GDtv7QvJl38uRAqBRK5Ec9CGC0brGZquX8UgHi1q1
1+NzHSt95E4Y0CKWPS48t+eO58MUE8v69gjLa9DdnhII4tCdAUURuP+AsaFm+hzP
a7OufMNnh/S8igDmqon0c9W6sJrkDo9DdrZPlu6MFjGQ5SbS6mSfvwSRKVd3RTCN
2/+uz0EwBygq1OKS+Z7Z+kx29UR8+bNXOGaPRlsr5CKcwVV9w3FBvEICuDaP75vj
l0d75+2R+CB/R/e2+dMMRCQY5MNWtYuuqoz3jNws59J+0z5K35usLoaKdB7Ez3D6
G2CCBKJSrugT0s8OkhX5pcTiU6NUIrq6q8h7JNEeuR0bniFClXlDrAs9iIdNb4PS
oFpqtNJWPLaicHRMnJdnxPCriHa0lmI3QVoGrf6UFtBAXuiOkFxcHUmTcQczyfOm
IGyGcgCko3o=
=djsT
-END PGP SIGNATURE-

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


  



--
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr

__
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] R-code in html help pages: syntax highlighting

2009-03-16 Thread Duncan Murdoch

On 3/16/2009 1:49 PM, Jose Quesada wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
 
Hi,


A follow up to my previous post. It'd be good to have syntax
highlighting in the html help pages. 


This needs two things:  making the highlight program available to R, and 
then adding it to the Rd to HTML conversion code.  In current releases 
that conversion is done in Perl code, but with R 2.9 an R-based 
converter will be available (but not used by default; too many CRAN 
packages have too many errors in their Rd files, and the new converter 
is more sensitive to such things).  So sometime after 2.9.0 is released, 
it would seem like a reasonable project to modify the conversion to 
allow for syntax highlighting.


One likely complaint is that the highlighting will be inaccurate. 
Typically highlighters just have a list of things they know to be 
important names, they don't actually take scoping rules into account (so 
mean gets highlighted as a built in function even when used as


mean - (x + y)/2

for example).  So it would be interesting if someone wanted to do the 
work to make a syntax highlighter that was accurate.  I'd say the R core 
work on something like this would be to provide the hook for a user to 
link in their own favourite highlighter; I doubt if we'd want to take on 
the bitching that the inaccurate highlighting would attract.


Duncan Murdoch


There is highlight

(http://www.andre-simon.de/) which seems to be open source. Since code
is delimited in the help file format, it should not be too difficult
to run a highlighting program (actually, vim and emacs do this too)
recursively and pretty-print all the R examples in the entire CRAN.
Including the highlighter with R, or whatever supplementary tools
people use to make R html help files could simplify things. I've never
written docs or released a package, so I may be understimating the
effort it'd take to get this working.

Using the r-help gmane archives also leads to plain code.
This is probably more trouble than it's worth, since there's no
metadata delimiting a block of code and it might be difficult... but
grepping through all R-help posts and coloring code would be really
nice too. Again, this lands straight into 'nice to have, but not
essential' territory.

If anyone wants to do this, feel free to.

Best,
- -J

- --
Jose Quesada, PhD.
Max Planck Institute,
Center for Adaptive Behavior and cognition,
Berlin
http://www.josequesada.name/   
-BEGIN PGP SIGNATURE-

Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iQIVAwUBSb6RRGMobUVGH+HKAQI2RxAAijNIj7qlBogc9M6lhQ2Ah1Px29iU/uzS

45t5blwNSGVSbAbZF7N7rRcBdn8/c4W8n+oI62nnap0snwLMFW/ynikVNJuBY+XA
+yNaO5nIJo5SWu60WkcMinm/ysPZ4o4Jdxr1+lGfJ/ceVSTWPWVLb//GN8QElgwT
Vf0ZQUSqfWczzeVDSDtfMKGTJOz4y60eF5hounA/PkzyUd8RRo1WpEXzJHYsCTI+
RwBrYZ5Q30cpKLAJQNeiiv8GDtv7QvJl38uRAqBRK5Ec9CGC0brGZquX8UgHi1q1
1+NzHSt95E4Y0CKWPS48t+eO58MUE8v69gjLa9DdnhII4tCdAUURuP+AsaFm+hzP
a7OufMNnh/S8igDmqon0c9W6sJrkDo9DdrZPlu6MFjGQ5SbS6mSfvwSRKVd3RTCN
2/+uz0EwBygq1OKS+Z7Z+kx29UR8+bNXOGaPRlsr5CKcwVV9w3FBvEICuDaP75vj
l0d75+2R+CB/R/e2+dMMRCQY5MNWtYuuqoz3jNws59J+0z5K35usLoaKdB7Ez3D6
G2CCBKJSrugT0s8OkhX5pcTiU6NUIrq6q8h7JNEeuR0bniFClXlDrAs9iIdNb4PS
oFpqtNJWPLaicHRMnJdnxPCriHa0lmI3QVoGrf6UFtBAXuiOkFxcHUmTcQczyfOm
IGyGcgCko3o=
=djsT
-END PGP SIGNATURE-

__
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] R-code in html help pages: syntax highlighting

2009-03-16 Thread Romain Francois

Duncan Murdoch wrote:

On 3/16/2009 1:49 PM, Jose Quesada wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
 
Hi,


A follow up to my previous post. It'd be good to have syntax
highlighting in the html help pages. 


This needs two things:  making the highlight program available to R, 
and then adding it to the Rd to HTML conversion code.  In current 
releases that conversion is done in Perl code, but with R 2.9 an 
R-based converter will be available (but not used by default; too many 
CRAN packages have too many errors in their Rd files, and the new 
converter is more sensitive to such things).  So sometime after 2.9.0 
is released, it would seem like a reasonable project to modify the 
conversion to allow for syntax highlighting.


One likely complaint is that the highlighting will be inaccurate. 
Typically highlighters just have a list of things they know to be 
important names, they don't actually take scoping rules into account 
(so mean gets highlighted as a built in function even when used as


mean - (x + y)/2

for example).  So it would be interesting if someone wanted to do the 
work to make a syntax highlighter that was accurate.  I'd say the R 
core work on something like this would be to provide the hook for a 
user to link in their own favourite highlighter; I doubt if we'd want 
to take on the bitching that the inaccurate highlighting would attract.

Hi Duncan,

It would be pretty easy to use the output from the R parser (which is 
never wrong, is it?), and dump some markup out of it. For example the 
showTree function in codetools dumps an R expression as Lisp, this is 
not too far from generating html, or any other markup.


As this sounds like fun, I'll volunteer to do something about this. 
Another advantage is that we can imagine to plug hyperlinks in  R code 
that lives in html help pages.


Romain


Duncan Murdoch


There is highlight

(http://www.andre-simon.de/) which seems to be open source. Since code
is delimited in the help file format, it should not be too difficult
to run a highlighting program (actually, vim and emacs do this too)
recursively and pretty-print all the R examples in the entire CRAN.
Including the highlighter with R, or whatever supplementary tools
people use to make R html help files could simplify things. I've never
written docs or released a package, so I may be understimating the
effort it'd take to get this working.

Using the r-help gmane archives also leads to plain code.
This is probably more trouble than it's worth, since there's no
metadata delimiting a block of code and it might be difficult... but
grepping through all R-help posts and coloring code would be really
nice too. Again, this lands straight into 'nice to have, but not
essential' territory.

If anyone wants to do this, feel free to.

Best,
- -J

- --
Jose Quesada, PhD.
Max Planck Institute,
Center for Adaptive Behavior and cognition,
Berlin
http://www.josequesada.name/   -BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iQIVAwUBSb6RRGMobUVGH+HKAQI2RxAAijNIj7qlBogc9M6lhQ2Ah1Px29iU/uzS

45t5blwNSGVSbAbZF7N7rRcBdn8/c4W8n+oI62nnap0snwLMFW/ynikVNJuBY+XA
+yNaO5nIJo5SWu60WkcMinm/ysPZ4o4Jdxr1+lGfJ/ceVSTWPWVLb//GN8QElgwT
Vf0ZQUSqfWczzeVDSDtfMKGTJOz4y60eF5hounA/PkzyUd8RRo1WpEXzJHYsCTI+
RwBrYZ5Q30cpKLAJQNeiiv8GDtv7QvJl38uRAqBRK5Ec9CGC0brGZquX8UgHi1q1
1+NzHSt95E4Y0CKWPS48t+eO58MUE8v69gjLa9DdnhII4tCdAUURuP+AsaFm+hzP
a7OufMNnh/S8igDmqon0c9W6sJrkDo9DdrZPlu6MFjGQ5SbS6mSfvwSRKVd3RTCN
2/+uz0EwBygq1OKS+Z7Z+kx29UR8+bNXOGaPRlsr5CKcwVV9w3FBvEICuDaP75vj
l0d75+2R+CB/R/e2+dMMRCQY5MNWtYuuqoz3jNws59J+0z5K35usLoaKdB7Ez3D6
G2CCBKJSrugT0s8OkhX5pcTiU6NUIrq6q8h7JNEeuR0bniFClXlDrAs9iIdNb4PS
oFpqtNJWPLaicHRMnJdnxPCriHa0lmI3QVoGrf6UFtBAXuiOkFxcHUmTcQczyfOm
IGyGcgCko3o=
=djsT
-END PGP SIGNATURE-

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





--
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr

__
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] R-code in html help pages: syntax highlighting

2009-03-16 Thread Duncan Murdoch

On 3/16/2009 2:50 PM, Romain Francois wrote:

Duncan Murdoch wrote:

On 3/16/2009 1:49 PM, Jose Quesada wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
 
Hi,


A follow up to my previous post. It'd be good to have syntax
highlighting in the html help pages. 


This needs two things:  making the highlight program available to R, 
and then adding it to the Rd to HTML conversion code.  In current 
releases that conversion is done in Perl code, but with R 2.9 an 
R-based converter will be available (but not used by default; too many 
CRAN packages have too many errors in their Rd files, and the new 
converter is more sensitive to such things).  So sometime after 2.9.0 
is released, it would seem like a reasonable project to modify the 
conversion to allow for syntax highlighting.


One likely complaint is that the highlighting will be inaccurate. 
Typically highlighters just have a list of things they know to be 
important names, they don't actually take scoping rules into account 
(so mean gets highlighted as a built in function even when used as


mean - (x + y)/2

for example).  So it would be interesting if someone wanted to do the 
work to make a syntax highlighter that was accurate.  I'd say the R 
core work on something like this would be to provide the hook for a 
user to link in their own favourite highlighter; I doubt if we'd want 
to take on the bitching that the inaccurate highlighting would attract.

Hi Duncan,

It would be pretty easy to use the output from the R parser (which is 
never wrong, is it?), and dump some markup out of it. For example the 
showTree function in codetools dumps an R expression as Lisp, this is 
not too far from generating html, or any other markup.


As this sounds like fun, I'll volunteer to do something about this. 
Another advantage is that we can imagine to plug hyperlinks in  R code 
that lives in html help pages.





That sounds great.  I'd be happy to work with you to add hooks to the 
conversion functions so your highlighters can be called (but not for a 
few weeks:  we're at a very busy time of year here).  But if you want to 
get started, and figure out what you need, getting in touch with me in 
early April would be fine.


Duncan Murdoch

__
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] R-code in html help pages: syntax highlighting

2009-03-16 Thread hadley wickham
 It would be pretty easy to use the output from the R parser (which is never
 wrong, is it?), and dump some markup out of it. For example the showTree
 function in codetools dumps an R expression as Lisp, this is not too far
 from generating html, or any other markup.

 As this sounds like fun, I'll volunteer to do something about this. Another
 advantage is that we can imagine to plug hyperlinks in  R code that lives in
 html help pages.

This also sounds like a good idea for a google summer of code project
- that way you might be able to get a student to give you a hand as
well.

Hadley

-- 
http://had.co.nz/

__
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] R-code in html help pages: syntax highlighting

2009-03-16 Thread Romain Francois

hadley wickham wrote:

It would be pretty easy to use the output from the R parser (which is never
wrong, is it?), and dump some markup out of it. For example the showTree
function in codetools dumps an R expression as Lisp, this is not too far
from generating html, or any other markup.

As this sounds like fun, I'll volunteer to do something about this. Another
advantage is that we can imagine to plug hyperlinks in  R code that lives in
html help pages.



This also sounds like a good idea for a google summer of code project
- that way you might be able to get a student to give you a hand as
well.

Hadley
  
That did cross my mind earlier this evening, it just seems a bit too 
easy to last all summer, but maybe I am missing something difficult. I 
will start to play with this over the next few days, and make up my mind.


One of the problem I might run into is performance, if we want this to 
treat all Rd files, we are going to want something very efficient, and 
it might not be enough to build on top of codetools (which uses 
recursion at the R level) , but could make sense to provide a C level 
implementation.


This could lead to interesting things as:
- syntax highlighting in sweave (or decumar)
- pretty printing in the console (using ansi characters)
- syntax highlighting in R help files, potentially with hyperlinks

I have requested creation of a project on r-forge. Anyone else want to 
play with this ?


Romain

--
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr

__
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] R-code in html help pages: syntax highlighting

2009-03-16 Thread Duncan Murdoch

On 16/03/2009 5:06 PM, Romain Francois wrote:

hadley wickham wrote:

It would be pretty easy to use the output from the R parser (which is never
wrong, is it?), and dump some markup out of it. For example the showTree
function in codetools dumps an R expression as Lisp, this is not too far
from generating html, or any other markup.

As this sounds like fun, I'll volunteer to do something about this. Another
advantage is that we can imagine to plug hyperlinks in  R code that lives in
html help pages.


This also sounds like a good idea for a google summer of code project
- that way you might be able to get a student to give you a hand as
well.

Hadley
  
That did cross my mind earlier this evening, it just seems a bit too 
easy to last all summer, but maybe I am missing something difficult. I 
will start to play with this over the next few days, and make up my mind.


It depends on your standards.  You said you want R to parse the code in 
the Rd file.  That's going to be hard, because Rd files contain 
something that is only R-like, as far as the parser is concerned. 
You'll need to convert it into R code before you can pass it to the R 
parser.


And then there's the question of scoping, which gets into the evaluator, 
not just the parser.  (The parser only recognizes mean as an 
identifier; it's the evaluator that decides whether it's the function in 
the base package or a local variable.)


So if you've got high standards, it's probably quite hard.  On the other 
hand, if you're willing to accept the usual sort of errors that syntax 
highlighters make, it's not so bad, but not trivial.


One of the problem I might run into is performance, if we want this to 
treat all Rd files, we are going to want something very efficient, and 
it might not be enough to build on top of codetools (which uses 
recursion at the R level) , but could make sense to provide a C level 
implementation.


Remember what Knuth said about premature optimization.  Write it first 
in R, and only optimize it if it's not fast enough.  (I'd guess it'll be 
fast enough:  Brian Ripley reported that all the R code he wrote for 
conversions in R-devel was faster than the Perl code it was replacing.)



This could lead to interesting things as:
- syntax highlighting in sweave (or decumar)
- pretty printing in the console (using ansi characters)
- syntax highlighting in R help files, potentially with hyperlinks

I have requested creation of a project on r-forge. Anyone else want to 
play with this ?


I'll sign up once it's going.

Duncan Murdoch

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