[R] Sweave and long strings

Roger Bivand Roger.Bivand at nhh.no
Sun Mar 5 14:27:22 CET 2006


On Sun, 5 Mar 2006, Laurent Rhelp wrote:

> Dear R-List,
> 
>     I use Sweave (which is wonderful) and I have a problem with the 
> strings when they are too long according to the width of the page. For 
> example when I do in my .Rnw document :
> 
> <<UsingRODBC,echo=TRUE>>=
> 
> channel <- odbcConnect(dsn="database",uid="root",pwd="password")
> df1 <- sqlFetch(channel,"table1",rownames=TRUE)
> df2 <- sqlFetch(channel,"table2",rownames=TRUE)
> 
> cmd <- "SELECT t1.isoisotope,
>                t1.periode,t1.nbZ,
>                t2.filnomchaineradio,
>                t2.filcodepere,
>                t2.filcodefils,
>                t2.filproba,
>                t2.filtransition from table1 t1,
>                                             table2 t2
>          WHERE t1.isoisotope = t2.filcodepere"
> 
> dfQuery <-  sqlQuery(channel, cmd )
> odbcCloseAll()
> 
> @
> 
> etc...
> 
> in the pdf document the command
> cmd <- "SELECT t1.isoisotope,  t1.periode,t1.nbZ,  
> t2.filnomchaineradio,  t2.filcodepere,  t2.filcodefils,
> is written truncated only on one line not as it is written in the chunk 
> above.
> 
> I read in the R-archives we have to use the options command but even 
> using options(width=30) in the chunk it doesn't work.

This is because it is a single string. Could you also say:

cmd <- paste("SELECT t1.isoisotope,",  
               "t1.periode,t1.nbZ,",
               "t2.filnomchaineradio,",
               "t2.filcodepere,",
               "t2.filcodefils,",
               "t2.filproba,",
               "t2.filtransition from table1 t1,",
                                            "table2 t2",
         "WHERE t1.isoisotope = t2.filcodepere")

or an equivalent with the included white space and line breaks? It will be 
parsed anyway inside Sweave, so at least using paste() should prevent it 
overrunning the right margin. 

> 
> May you help me ?
> 
> Thanks
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-help mailing list