[R] Output In R

John Kane jrkrideau at inbox.com
Sat Aug 22 16:33:16 CEST 2015


Hi Shivi,
A correction to my latex/knitr code.  I stupidly forgot the initial problem was the length of the data set.  To get it to print correctly we need to use the LaTeX package 'longtable'.  Clearly too many trees for me to see the forest.
Add \usepackage{longtable} to the Preamble.

#==========Revised code for knitr/R========
<<atable, echo=FALSE, results="asis">>=
library(xtable) 
dat1  <-  data.frame(matrix( rnorm(2000), ncol = 5))
dat1.table  <-  xtable(dat1)
print(dat1.table,tabular.environment='longtable',
floating = FALSE,
include.rownames=FALSE,
booktabs = TRUE)
@
#==============end===================

John Kane
Kingston ON Canada


> -----Original Message-----
> From: jrkrideau at inbox.com
> Sent: Sat, 22 Aug 2015 05:49:32 -0800
> To: shivibhatia at ymail.com, r-help at r-project.org
> Subject: Re: [R] Output In R
> 
> We are talking at cross-purposes here because SAS and R are radically
> different beasts. Just about everything you did in SAS does not work / is
> wrong /i s illegal/ is immoral / and possibly fattening.
> 
> If you have not seen it, you may find Bob Muenchen's pdf and/or the
> expanded book R FOR SAS AND SPSS USERS (
https://science.nature.nps.gov/im/datamgmt/statistics/R/documents/R_for_SAS_SPSS_users.pdf
> ) useful.
> 
> It is very easy to create the data set you want. You just need to think
> in R's somewhat twisted way.  Well if twisted my mind for the first 6
> weeks that I used it.
> 
> Let's say you are doing some analysis. Don't send the data to the
> console. Instead save it in a R object (not sure if this is the correct
> term--I am sure the purists will correct me.)
> 
> 
> I am going to create a data.frame called dat1 (pretend it is your data).
> 
> 
> #create make-believe data
> dat1  <-  data.frame(matrix( rnorm(100), ncol = 5))
> 
> #Save dat1 as an R file. Handy for your work not great as a way
> #to pass around data unless the client knows R and has R installed
> 
> save( dat1, file = "~/Rjunk/ mydata.RData")
> 
> #Save as a .csv file. Fast easy and can be opened in any
> #text editor, spreadsheet or even a word processor.
> 
> write.csv(dat1, file = "~/Rjunk/ mydata.csv")
> 
> 
> 
> To produce a Latex file and get a pdf.
> 
> One starts with a  .Rnw (i.e. plain text with a .Rnw suffix)  file and
> then compiles it.
> I used the command  Rscript -e "library(knitr); knit('./Shiv1.Rnw')"
> where Shiv.Rnw was my LaTeX / knitr file.  It is easier and faster to use
> RStudio for  this.
> 
> You will probably need to install the xtable package and depending in
> your LaTeX version you may need to install booktabs.
> 
> ########Start Latex file###################
> \documentclass[12pt,letterpaper]{article}
> \usepackage[utf8]{inputenc}
> \usepackage{booktabs}
> \title{Magnum Opus Meum}
> \author{jrkrideau }
> \begin{document}
> 
> \maketitle
> 
> <<atable, echo=FALSE, results="asis">>=
> library(xtable)
> dat1  <-  data.frame(matrix( rnorm(100), ncol = 5))
> dat1.table  <-  xtable(dat1)
> print(dat1.table,
> include.rownames=FALSE,
> booktabs = TRUE)
> @
> 
> \end{document}
> 
> ########End Latex file####################
> 
> John Kane
> Kingston ON Canada
> 
> 
>> -----Original Message-----
>> From: shivibhatia at ymail.com
>> Sent: Fri, 21 Aug 2015 12:26:50 -0700 (PDT)
>> To: r-help at r-project.org
>> Subject: Re: [R] Output In R
>> 
>> Thanks Jeff, this is helpful.
>> The reason i am curious to know this is because I have worked for a long
>> duration in SAS where in it gives us the flexibility to create a data
>> set
>> of
>> our analysis and then we can easily detail out the same to the end user.
>> 
>> In R seems like View or Sweave  or Shiny are the alternative.
>> 
>> 
>> 
>> 
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/Output-In-R-tp4711227p4711368.html
>> Sent from the R help mailing list archive at Nabble.com.
>> 
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
> 
> ____________________________________________________________
> FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on
> your desktop!
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!



More information about the R-help mailing list