I have used Sweave a lot the latest year, but never really used any long
function calls.
If I have code which look like this
-------------------------------------------------------------
gof <- benthic.flux(ID="Gulf of Finland",
meas.conc=conc,
bw.conc=bw.conc,
time=times,
substance=expression(DIC~(mmol~m^{-3}))
)
-------------------------------------------------------------
I get the output by Sweave in my pdf file, like this:
---------------------------------------------------------------
> gof <- benthic.flux(ID = "Gulf of Finland", meas.conc = conc,
+ bw.conc = bw.conc, time = times, substance = expression(DIC ~
+ (mmol ~ m^{
+ -3
+ })))
----------------------------------------------------------------
I can understand that it will not look exactly as entered but why is the
'-3' on a line of it's own?
Can anyone suggest a idea to how I can make this more readable.
---------------------------------------------
Henrik Andersson
Netherlands Institute of Ecology -
Centre for Estuarine and Marine Ecology
P.O. Box 140
4400 AC Yerseke
Phone: +31 113 577473
h.andersson at nioo.knaw.nl
http://www.nioo.knaw.nl/ppages/handersson
Long lines with Sweave
7 messages · Henrik Andersson, Jan T. Kim, Martin Maechler +1 more
On Wed, Sep 14, 2005 at 10:14:59AM +0200, Henrik Andersson wrote:
I have used Sweave a lot the latest year, but never really used any long
function calls.
If I have code which look like this
-------------------------------------------------------------
gof <- benthic.flux(ID="Gulf of Finland",
meas.conc=conc,
bw.conc=bw.conc,
time=times,
substance=expression(DIC~(mmol~m^{-3}))
)
-------------------------------------------------------------
I get the output by Sweave in my pdf file, like this:
---------------------------------------------------------------
> gof <- benthic.flux(ID = "Gulf of Finland", meas.conc = conc,
+ bw.conc = bw.conc, time = times, substance = expression(DIC ~
+ (mmol ~ m^{
+ -3
+ })))
----------------------------------------------------------------
I can understand that it will not look exactly as entered but why is the
'-3' on a line of it's own?
Can anyone suggest a idea to how I can make this more readable.
It seems you've been thinking LaTeX rather than R ;-) :
The exponent "-3" in the expression should be enclosed by parentheses
rather than by curly braces.
The code formatting done by the print method inserts the newline after
"{" and before "}".
Best regards, Jan
+- Jan T. Kim -------------------------------------------------------+ | *NEW* email: jtk at cmp.uea.ac.uk | | *NEW* WWW: http://www.cmp.uea.ac.uk/people/jtk | *-----=< hierarchical systems are for files, not for humans >=-----*
Jan T. Kim wrote:
On Wed, Sep 14, 2005 at 10:14:59AM +0200, Henrik Andersson wrote:
I have used Sweave a lot the latest year, but never really used any long
function calls.
If I have code which look like this
-------------------------------------------------------------
gof <- benthic.flux(ID="Gulf of Finland",
meas.conc=conc,
bw.conc=bw.conc,
time=times,
substance=expression(DIC~(mmol~m^{-3}))
)
-------------------------------------------------------------
I get the output by Sweave in my pdf file, like this:
---------------------------------------------------------------
gof <- benthic.flux(ID = "Gulf of Finland", meas.conc = conc,
+ bw.conc = bw.conc, time = times, substance = expression(DIC ~
+ (mmol ~ m^{
+ -3
+ })))
----------------------------------------------------------------
I can understand that it will not look exactly as entered but why is the
'-3' on a line of it's own?
Can anyone suggest a idea to how I can make this more readable.
It seems you've been thinking LaTeX rather than R ;-) :
The exponent "-3" in the expression should be enclosed by parentheses
rather than by curly braces.
The code formatting done by the print method inserts the newline after
"{" and before "}".
Best regards, Jan
If you look at demo(plotmath), I get the impression that m^(-3) does not give me the desired behavior. I want to have -3 in superscript without visible parentheses. Tricky! --------------------------------------------- Henrik Andersson Netherlands Institute of Ecology - Centre for Estuarine and Marine Ecology P.O. Box 140 4400 AC Yerseke Phone: +31 113 577473 h.andersson at nioo.knaw.nl http://www.nioo.knaw.nl/ppages/handersson
On Wed, Sep 14, 2005 at 02:49:56PM +0200, Henrik Andersson wrote:
Jan T. Kim wrote:
On Wed, Sep 14, 2005 at 10:14:59AM +0200, Henrik Andersson wrote:
I have used Sweave a lot the latest year, but never really used any long
function calls.
If I have code which look like this
-------------------------------------------------------------
gof <- benthic.flux(ID="Gulf of Finland",
meas.conc=conc,
bw.conc=bw.conc,
time=times,
substance=expression(DIC~(mmol~m^{-3}))
)
-------------------------------------------------------------
I get the output by Sweave in my pdf file, like this:
---------------------------------------------------------------
gof <- benthic.flux(ID = "Gulf of Finland", meas.conc = conc,
+ bw.conc = bw.conc, time = times, substance = expression(DIC ~
+ (mmol ~ m^{
+ -3
+ })))
----------------------------------------------------------------
I can understand that it will not look exactly as entered but why is the
'-3' on a line of it's own?
Can anyone suggest a idea to how I can make this more readable.
It seems you've been thinking LaTeX rather than R ;-) :
The exponent "-3" in the expression should be enclosed by parentheses
rather than by curly braces.
The code formatting done by the print method inserts the newline after
"{" and before "}".
Best regards, Jan
If you look at demo(plotmath), I get the impression that m^(-3) does not give me the desired behavior. I want to have -3 in superscript without visible parentheses. Tricky!
Ok, I see.
It seems to me that you could omit the curly braces in the example, I
don't see any differences between the title in the plots produced by
plot(1:10, main = expression(DIC~(mmol~m^-3)))
and
plot(1:10, main = expression(DIC~(mmol~m^{-3})))
For more complex exponents, you could try plain() to prevent them from
being wrongly grouped by operator precedence, as in
plot(1:10, main = expression(DIC~(mmol~m^plain(-3 + t))))
Not exactly ideal for readability, however...
Best regards, Jan
+- Jan T. Kim -------------------------------------------------------+ | *NEW* email: jtk at cmp.uea.ac.uk | | *NEW* WWW: http://www.cmp.uea.ac.uk/people/jtk | *-----=< hierarchical systems are for files, not for humans >=-----*
"Jan" == Jan T Kim <jtk at cmp.uea.ac.uk>
on Wed, 14 Sep 2005 14:46:20 +0100 writes:
Jan> On Wed, Sep 14, 2005 at 02:49:56PM +0200, Henrik Andersson wrote:
>> Jan T. Kim wrote:
>> > On Wed, Sep 14, 2005 at 10:14:59AM +0200, Henrik Andersson wrote:
>> >
>> >>I have used Sweave a lot the latest year, but never really used any long
>> >>function calls.
>> >>
>> >>
>> >>If I have code which look like this
>> >>
>> >>-------------------------------------------------------------
>> >>gof <- benthic.flux(ID="Gulf of Finland",
>> >> meas.conc=conc,
>> >> bw.conc=bw.conc,
>> >> time=times,
>> >> substance=expression(DIC~(mmol~m^{-3}))
>> >> )
>> >>-------------------------------------------------------------
>> >>
>> >>I get the output by Sweave in my pdf file, like this:
>> >>
>> >>---------------------------------------------------------------
>> >> > gof <- benthic.flux(ID = "Gulf of Finland", meas.conc = conc,
>> >>+ bw.conc = bw.conc, time = times, substance = expression(DIC ~
>> >>+ (mmol ~ m^{
>> >>+ -3
>> >>+ })))
>> >>----------------------------------------------------------------
>> >>
>> >>I can understand that it will not look exactly as entered but why is the
>> >>'-3' on a line of it's own?
>> >>
>> >>Can anyone suggest a idea to how I can make this more readable.
>> >
>> >
>> > It seems you've been thinking LaTeX rather than R ;-) :
>> > The exponent "-3" in the expression should be enclosed by parentheses
>> > rather than by curly braces.
>> >
>> > The code formatting done by the print method inserts the newline after
>> > "{" and before "}".
>> >
>> > Best regards, Jan
>>
>> If you look at demo(plotmath), I get the impression that m^(-3) does not
>> give me the desired behavior.
>>
>> I want to have -3 in superscript without visible parentheses.
>>
>> Tricky!
Jan> Ok, I see.
Jan> It seems to me that you could omit the curly braces in the example, I
Jan> don't see any differences between the title in the plots produced by
Jan> plot(1:10, main = expression(DIC~(mmol~m^-3)))
Jan> and
Jan> plot(1:10, main = expression(DIC~(mmol~m^{-3})))
Jan> For more complex exponents, you could try plain() to prevent them from
Jan> being wrongly grouped by operator precedence, as in
Jan> plot(1:10, main = expression(DIC~(mmol~m^plain(-3 + t))))
neat idea, but
Jan> Not exactly ideal for readability, however...
indeed. And really only a workaround:
You shouldn't have to uglify your R code in order to work around
Sweave "pecularities".
Martin
On Thu, 15 Sep 2005 09:35:25 +0200, Martin Maechler (MM) wrote:
"Jan" == Jan T Kim <jtk at cmp.uea.ac.uk>
on Wed, 14 Sep 2005 14:46:20 +0100 writes:
Jan> On Wed, Sep 14, 2005 at 02:49:56PM +0200, Henrik Andersson wrote:
>>> Jan T. Kim wrote:
>>> > On Wed, Sep 14, 2005 at 10:14:59AM +0200, Henrik Andersson wrote:
>>> >
>>> >>I have used Sweave a lot the latest year, but never really used any long
>>> >>function calls.
>>> >>
>>> >>
>>> >>If I have code which look like this
>>> >>
>>> >>-------------------------------------------------------------
>>> >>gof <- benthic.flux(ID="Gulf of Finland",
>>> >> meas.conc=conc,
>>> >> bw.conc=bw.conc,
>>> >> time=times,
>>> >> substance=expression(DIC~(mmol~m^{-3}))
>>> >> )
>>> >>-------------------------------------------------------------
>>> >>
>>> >>I get the output by Sweave in my pdf file, like this:
>>> >>
>>> >>---------------------------------------------------------------
>>> >> > gof <- benthic.flux(ID = "Gulf of Finland", meas.conc = conc,
>>> >>+ bw.conc = bw.conc, time = times, substance = expression(DIC ~
>>> >>+ (mmol ~ m^{
>>> >>+ -3
>>> >>+ })))
>>> >>----------------------------------------------------------------
>>> >>
>>> >>I can understand that it will not look exactly as entered but why is the
>>> >>'-3' on a line of it's own?
>>> >>
>>> >>Can anyone suggest a idea to how I can make this more readable.
>>> >
>>> >
>>> > It seems you've been thinking LaTeX rather than R ;-) :
>>> > The exponent "-3" in the expression should be enclosed by parentheses
>>> > rather than by curly braces.
>>> >
>>> > The code formatting done by the print method inserts the newline after
>>> > "{" and before "}".
>>> >
>>> > Best regards, Jan
>>>
>>> If you look at demo(plotmath), I get the impression that m^(-3) does not
>>> give me the desired behavior.
>>>
>>> I want to have -3 in superscript without visible parentheses.
>>>
>>> Tricky!
Jan> Ok, I see.
Jan> It seems to me that you could omit the curly braces in the example, I
Jan> don't see any differences between the title in the plots produced by
Jan> plot(1:10, main = expression(DIC~(mmol~m^-3)))
Jan> and
Jan> plot(1:10, main = expression(DIC~(mmol~m^{-3})))
Jan> For more complex exponents, you could try plain() to prevent them from
Jan> being wrongly grouped by operator precedence, as in
Jan> plot(1:10, main = expression(DIC~(mmol~m^plain(-3 + t))))
> neat idea, but
Jan> Not exactly ideal for readability, however...
> indeed. And really only a workaround:
> You shouldn't have to uglify your R code in order to work around
> Sweave "pecularities".
Hmm, it's not really an "Sweave peculiarity", but one of the R
parser. After saving Henrik's code in file test.R I get
R> x = parse("test.R")
R> x
expression(gof <- benthic.flux(ID = "Gulf of Finland", meas.conc = conc,
bw.conc = bw.conc, time = times, substance = expression(DIC ~
(mmol ~ m^{
-3
}))))
R> deparse(x)
[1] "expression(gof <- benthic.flux(ID = \"Gulf of Finland\", meas.conc = conc, "
[2] " bw.conc = bw.conc, time = times, substance = expression(DIC ~ "
[3] " (mmol ~ m^{"
[4] " -3"
[5] " }))))"
and the latter is used by Sweave. The code chunks need to be parsed,
because otherwise there is no way how to know where to insert
output. A source(..., echo=TRUE) will suffer from the same problem.
Best,
Fritz
-------------------------------------------------------------------
Friedrich Leisch
Institut f??r Statistik Tel: (+43 1) 58801 10715
Technische Universit??t Wien Fax: (+43 1) 58801 10798
Wiedner Hauptstra??e 8-10/1071
A-1040 Wien, Austria http://www.ci.tuwien.ac.at/~leisch
"Fritz" == Friedrich Leisch <Friedrich.Leisch at tuwien.ac.at>
on Thu, 15 Sep 2005 10:36:43 +0200 writes:
On Thu, 15 Sep 2005 09:35:25 +0200, Martin Maechler (MM) wrote:
"Jan" == Jan T Kim <jtk at cmp.uea.ac.uk>
on Wed, 14 Sep 2005 14:46:20 +0100 writes:
Jan> On Wed, Sep 14, 2005 at 02:49:56PM +0200, Henrik Andersson wrote:
>>>> Jan T. Kim wrote:
>>>> > On Wed, Sep 14, 2005 at 10:14:59AM +0200, Henrik Andersson wrote:
>>>> >
>>>> >>I have used Sweave a lot the latest year, but never really used any long
>>>> >>function calls.
>>>> >>
>>>> >>
>>>> >>If I have code which look like this
>>>> >>
>>>> >>-------------------------------------------------------------
>>>> >>gof <- benthic.flux(ID="Gulf of Finland",
>>>> >> meas.conc=conc,
>>>> >> bw.conc=bw.conc,
>>>> >> time=times,
>>>> >> substance=expression(DIC~(mmol~m^{-3}))
>>>> >> )
>>>> >>-------------------------------------------------------------
>>>> >>
>>>> >>I get the output by Sweave in my pdf file, like this:
>>>> >>
>>>> >>---------------------------------------------------------------
>>>> >> > gof <- benthic.flux(ID = "Gulf of Finland", meas.conc = conc,
>>>> >>+ bw.conc = bw.conc, time = times, substance = expression(DIC ~
>>>> >>+ (mmol ~ m^{
>>>> >>+ -3
>>>> >>+ })))
>>>> >>----------------------------------------------------------------
>>>> >>
>>>> >>I can understand that it will not look exactly as entered but why is the
>>>> >>'-3' on a line of it's own?
>>>> >>
>>>> >>Can anyone suggest a idea to how I can make this more readable.
>>>> >
>>>> >
>>>> > It seems you've been thinking LaTeX rather than R ;-) :
>>>> > The exponent "-3" in the expression should be enclosed by parentheses
>>>> > rather than by curly braces.
>>>> >
>>>> > The code formatting done by the print method inserts the newline after
>>>> > "{" and before "}".
>>>> >
>>>> > Best regards, Jan
>>>>
>>>> If you look at demo(plotmath), I get the impression that m^(-3) does not
>>>> give me the desired behavior.
>>>>
>>>> I want to have -3 in superscript without visible parentheses.
>>>>
>>>> Tricky!
Jan> Ok, I see.
Jan> It seems to me that you could omit the curly braces in the example, I
Jan> don't see any differences between the title in the plots produced by
Jan> plot(1:10, main = expression(DIC~(mmol~m^-3)))
Jan> and
Jan> plot(1:10, main = expression(DIC~(mmol~m^{-3})))
Jan> For more complex exponents, you could try plain() to prevent them from
Jan> being wrongly grouped by operator precedence, as in
Jan> plot(1:10, main = expression(DIC~(mmol~m^plain(-3 + t))))
>> neat idea, but
Jan> Not exactly ideal for readability, however...
>> indeed. And really only a workaround:
>> You shouldn't have to uglify your R code in order to work around
>> Sweave "pecularities".
Fritz> Hmm, it's not really an "Sweave peculiarity", but one of the R
Fritz> parser.
Indeed, of course -- it's R's internal deparse(.) :
Here's a smaller example:
(cc <- expression(x ^ {-3})[[1]])
str(as.list(cc))
List of 3
$ : symbol ^
$ : symbol x
$ : language { -3 }
Please apologize for any bad light that I might have shed on Sweave. I do love its concept! Martin