On 26/03/2012 9:30 AM, John C Nash wrote:
Yihui is correct that an error is generated. I should have mentioned that this
is
something I wanted to show in a vignette, and I got 103 characters as the
length of the
maximal line from a sink() file. Yihui's use of nchar is more elegant.
Thus the question remains of how to avoid margin over-run in the vignette
output. I've
seen this several times now, and there are some postings on the web that look
like they
are from the same source, but apart from options(width = ...) not found a
solution. I can
edit the Sweave output .tex file, but that seems a bit drastic and contrary to
the spirit
of reproducible research tools.
Possibilities:
- Can margins in Sweave (or knitr) be forced?
- Can the fixed width font size be adjusted easily?
Sweave uses the Latex fancyvrb package to put together its Sinput and
Soutput environments. That package is quite flexible so font size can
be adjusted, but I don't think it will do wrapping for you. That's
currently something you have to do manually (e.g. use capture.output()
to get the output, manipulate it, then use cat() to print it in a chunk
with echo=FALSE).
I think this (untested Latex code) would work to shrink the output:
\RecustomVerbatimEnvironment{Soutput}{Soutput}{fontsize=\small}
Duncan Murdoch
JN
On 03/25/2012 10:41 PM, Yihui Xie wrote:
> I got an error message:
>
>> options(width=60)
>> pastured<- data.frame(
> + time=c(9, 14, 21, 28, 42, 57, 63, 70, 79),
> + yield= c(8.93, 10.8, 18.59, 22.33, 39.35,
> + 56.11, 61.73, 64.62, 67.08))
>> regmod<-"yield ~ t1 - t2*exp(-exp(t3+t4*log(time)))"
>> huetstart<-c(t1=70, t2=60, t3=0, t4=1)
>> anlsx<-try(nls(regmod, start=huetstart, trace=TRUE, data=pastured))
> 13386.91 : 70 60 0 1
> Error in nls(regmod, start = huetstart, trace = TRUE, data = pastured) :
> singular gradient
>> print(anlsx)
> [1] "Error in nls(regmod, start = huetstart, trace = TRUE, data =
> pastured) : \n singular gradient\n"
> attr(,"class")
> [1] "try-error"
> attr(,"condition")
> <simpleError in nls(regmod, start = huetstart, trace = TRUE, data =
> pastured): singular gradient>
>
>
> and I see the number of characters of the message string is 94:
>
>> nchar(anlsx)
> [1] 94
>
> options(width) is not supposed to _wrap_ your character scalars; it
> cannot break a single string into several lines (use strwrap() instead
> in that case). See ?options for the exact meaning of the width option.
>
> # this may help you understand 'width'
> options(width = 50)
> rep(1, 100)
>
> options(width = 90)
> rep(1, 100)
>
>
> Regards,
> Yihui
> --
> Yihui Xie<xieyi...@gmail.com>
> Phone: 515-294-2465 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
>
>
>
> On Sun, Mar 25, 2012 at 9:17 PM, John C Nash<nas...@uottawa.ca> wrote:
>> The following example gives output with a line length of 103 on my system.
It is causing a
>> nuisance in creating a vignette. Is there something other than e.g.,
options(width=60) I
>> need to set? The Sweave FAQ suggests this should work.
>>
>> options(width=60)
>> pastured<- data.frame(
>> time=c(9, 14, 21, 28, 42, 57, 63, 70, 79),
>> yield= c(8.93, 10.8, 18.59, 22.33, 39.35,
>> 56.11, 61.73, 64.62, 67.08))
>> regmod<-"yield ~ t1 - t2*exp(-exp(t3+t4*log(time)))"
>> huetstart<-c(t1=70, t2=60, t3=0, t4=1)
>> anlsx<-try(nls(regmod, start=huetstart, trace=TRUE, data=pastured))
>> print(anlsx)
>>
>>
>> John Nash
>>
>> ______________________________________________
>> 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.
______________________________________________
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.