Re: [R] Transfer Crosstable to Word-Document
I must admit it's a very bad practice, but if you put these files in a separate folder, and you know what you have been busy with, I think it's less important. At least it saves you some mouse clicks But Philippe, you are absolutely rigth about the bad practice! Bart Philippe Grosjean wrote: > > > > Yes, but it is a very bad practice to name a file with .xls extension > that is not in Excel file format (here, a tab-separated ASCII file)! > Best, > > Philippe Grosjean > > > -- View this message in context: http://www.nabble.com/Transfer-Crosstable-to-Word-Document-tp15504150p15632864.html Sent from the R help mailing list archive at Nabble.com. __ 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] Transfer Crosstable to Word-Document
bartjoosen wrote: > > > Greg Snow-2 wrote: >> >>> write.table(my.data, 'clipboard', sep="\t") >> Then in Excel just do a paste and the data is there, this saves a couple >> of steps from saving as a .csv file and importing that into excel. This >> would probably be fine for a few tables. >> >> >> > > Just to inform: > > if you use write.table(my.data,'whateverfile.xls',sep="\t", quote=FALSE), > you can open this file right from the windows explorer as a normal excel > file. > If you're already running excel and choose file>open, you will get a dialog > box, where you have to click complete or OK. > > > Bart Yes, but it is a very bad practice to name a file with .xls extension that is not in Excel file format (here, a tab-separated ASCII file)! Best, Philippe Grosjean __ 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] Transfer Crosstable to Word-Document
I don't use Word much but an xtable (html) seems to import with no trouble. Thanks for reminding me that it works well with OOo. --- Peter Dalgaard <[EMAIL PROTECTED]> wrote: > Gabor Grothendieck wrote: > > On Feb 16, 2008 5:28 PM, David Scott > <[EMAIL PROTECTED]> wrote: > > > >> On Sat, 16 Feb 2008, Alan Zaslavsky wrote: > >> > >> > >>> If you want to get nicely formatted tables in > Word and are familiar with > >>> Office tools (I know it's the Evil Empire but > some of us work there), I > >>> suggest that you use Excel for formatting and > then insert the table into > >>> your Word document. IMHO, Excel is much > superior to Word for table > >>> formatting, e.g. modifying number of significant > digits, playing around > >>> with fonts and number formats, etc. And when > you have gotten the formats > >>> right you can paste in modified values of the > numbers in the table without > >>> having to do the formatting again. Including > the table in your Word > >>> document is easy by cut-paste or creating a live > link. > >>> > >>> As a user of R under Unix I haven't looked into > the facilities for writing > >>> tables to Excel under Windows but there is > something there. Alternatively > >>> you can write a fixed-column or tab-delimited > file and easily import to > >>> Excel. > >>> > >>> > >> Production of tables and formatting them in Word > is something I have dealt > >> with a couple of times recently and it really is > important to do something > >> smart because of the time taken to individually > format tables. > >> > >> An approach I used recently was to produce a text > table in R and export it > >> to Excel as a .csv file which could then be > copied as is to Word. Borders > >> and the like would still have to be formatted > individually but not entries > >> > > > > You could get a border automatically by writing > your table out > > as HTML. Try this using the builtin data frame > iris: > > > > library(R2HTML) > > HTML(iris, border = 1, file("clipboard","w"), > append=FALSE) > > > > Now paste that into Excel and from Excel into Word > and you should > > have a border around it. > > > > See ?HTML.data.frame > > > > You could alternately generate the HTML yourself > giving quite a bit > > of control. > > > Just curious (I don't use Word if I can help it -- > even the simplest of > things drive me up the wall), but can you not import > HTML directly in > Word? OpenOffice seems to do it quite happily with > xtable output. > > -- >O__ Peter Dalgaard Øster > Farimagsgade 5, Entr.B > c/ /'_ --- Dept. of Biostatistics PO Box 2099, > 1014 Cph. K > (*) \(*) -- University of Copenhagen Denmark > Ph: (+45) 35327918 > ~~ - ([EMAIL PROTECTED]) > FAX: (+45) 35327907 > > __ > 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] Transfer Crosstable to Word-Document
Greg Snow-2 wrote: > > >> write.table(my.data, 'clipboard', sep="\t") > > Then in Excel just do a paste and the data is there, this saves a couple > of steps from saving as a .csv file and importing that into excel. This > would probably be fine for a few tables. > > > Just to inform: if you use write.table(my.data,'whateverfile.xls',sep="\t", quote=FALSE), you can open this file right from the windows explorer as a normal excel file. If you're already running excel and choose file>open, you will get a dialog box, where you have to click complete or OK. Bart -- View this message in context: http://www.nabble.com/Transfer-Crosstable-to-Word-Document-tp15504150p15586769.html Sent from the R help mailing list archive at Nabble.com. __ 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] Transfer Crosstable to Word-Document
Greg, thank you for the nice overview, which is very helpful. Today I tested the HTML-Tool (Hmisc-library). First I had to install the HeVea translater (it´s a little bit tricky). I could produce a little html-table (it made me happy). I will be out of office until monday - it would be nice to continue our communication next week. Thanks to you and all list members! Udo Zitat von Greg Snow <[EMAIL PROTECTED]>: > There are several options available to you depending on your knowledge and > workflow. > > Others have mentioned using Excel to format the table and to copy that into > word, one thing along those lines that has not been mentioned yet is that if > you have your data in a matrix or data frame then (on windows at least, I > have not tried on other platforms) you can type: > > > write.table(my.data, 'clipboard', sep="\t") > > Then in Excel just do a paste and the data is there, this saves a couple of > steps from saving as a .csv file and importing that into excel. This would > probably be fine for a few tables. > > With a little effort on your part, odfWeave may still be an option. I have a > project based on a survey with quite a few questions, but the output wanted > was basically one of 3 tables and graphs based on a question or set of > questions. I wrote a set of functions that found the correct columns in the > data and created a matrix with the appropriate table values and used the > odfTable function to do the formating (and a set of functions to do the > graphs). Then I created an odf template file in OpenOffice that called the > appropriate functions for each question, ran that through odfWeave, opened > the result in OpenOffice and saved it as a word file to send to the clients. > Another nice thing about this approach is that occasionally I get requests > for the same output on a subset of the data, I just create the subset, rerun > odfWeave, convert to word and I'm done (I don't let the client know that it > was that easy though). I think there is something in the works to allow > conversion of odf files to ms word files from a command line. > > You can also use the existing LaTeX tools that others have suggested, then > convert from latex to HTML or RTF or another format that can be read into > word. If you take this approach wich will require a few intermediate steps > between R and word, then you may want to learn the make utility (there are > versions of make available on windows, otherwise I don't know how I would > survive trapped in an MS workplace). Make helps with automating several step > processes and updating only those parts that need to be updated. > > If you can give some more detail on what you want to do and how you want the > output to look, then we can give more specific ideas on how to get there. > > Hope this helps, > > -- > Gregory (Greg) L. Snow Ph.D. > Statistical Data Center > Intermountain Healthcare > [EMAIL PROTECTED] > (801) 408-8111 > > > > > -----Original Message- > > From: Udo König [mailto:[EMAIL PROTECTED] > > Sent: Sunday, February 17, 2008 11:08 AM > > To: r-help@r-project.org > > Cc: Greg Snow > > Subject: RE: [R] Transfer Crosstable to Word-Document > > > > Zitat von Greg Snow <[EMAIL PROTECTED]>: > > > > > If your final goal is a word document, then you should look at the > > > odfWeave package. > > > > Greg, > > I had a look at the odfWeave package, but it seems that > > complex tables, for instance produced with latex() can´t > > be produced/included, as can be done with sweave. > > > > > > > > Udo König > > Clinic for Child an Adolescent Psychiatry Philipps University > > of Marburg / Germany > > > > > > This message was sent using IMP, the Internet Messaging Program. > > > > > > Udo König Clinic for Child an Adolescent Psychiatry Philipps University of Marburg / Germany __ 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] Transfer Crosstable to Word-Document
There are several options available to you depending on your knowledge and workflow. Others have mentioned using Excel to format the table and to copy that into word, one thing along those lines that has not been mentioned yet is that if you have your data in a matrix or data frame then (on windows at least, I have not tried on other platforms) you can type: > write.table(my.data, 'clipboard', sep="\t") Then in Excel just do a paste and the data is there, this saves a couple of steps from saving as a .csv file and importing that into excel. This would probably be fine for a few tables. With a little effort on your part, odfWeave may still be an option. I have a project based on a survey with quite a few questions, but the output wanted was basically one of 3 tables and graphs based on a question or set of questions. I wrote a set of functions that found the correct columns in the data and created a matrix with the appropriate table values and used the odfTable function to do the formating (and a set of functions to do the graphs). Then I created an odf template file in OpenOffice that called the appropriate functions for each question, ran that through odfWeave, opened the result in OpenOffice and saved it as a word file to send to the clients. Another nice thing about this approach is that occasionally I get requests for the same output on a subset of the data, I just create the subset, rerun odfWeave, convert to word and I'm done (I don't let the client know that it was that easy though). I think there is something in the works to allow conversion of odf files to ms word files from a command line. You can also use the existing LaTeX tools that others have suggested, then convert from latex to HTML or RTF or another format that can be read into word. If you take this approach wich will require a few intermediate steps between R and word, then you may want to learn the make utility (there are versions of make available on windows, otherwise I don't know how I would survive trapped in an MS workplace). Make helps with automating several step processes and updating only those parts that need to be updated. If you can give some more detail on what you want to do and how you want the output to look, then we can give more specific ideas on how to get there. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 > -Original Message- > From: Udo König [mailto:[EMAIL PROTECTED] > Sent: Sunday, February 17, 2008 11:08 AM > To: r-help@r-project.org > Cc: Greg Snow > Subject: RE: [R] Transfer Crosstable to Word-Document > > Zitat von Greg Snow <[EMAIL PROTECTED]>: > > > If your final goal is a word document, then you should look at the > > odfWeave package. > > Greg, > I had a look at the odfWeave package, but it seems that > complex tables, for instance produced with latex() can´t > be produced/included, as can be done with sweave. > > > > Udo König > Clinic for Child an Adolescent Psychiatry Philipps University > of Marburg / Germany > > > This message was sent using IMP, the Internet Messaging Program. > > __ 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] Transfer Crosstable to Word-Document
Zitat von Greg Snow <[EMAIL PROTECTED]>: > If your final goal is a word document, then you should look at the odfWeave > package. Greg, I had a look at the odfWeave package, but it seems that complex tables, for instance produced with latex() can´t be produced/included, as can be done with sweave. Udo König Clinic for Child an Adolescent Psychiatry Philipps University of Marburg / Germany __ 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] Transfer Crosstable to Word-Document
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 You can programmatically create content directly in Word from R including tables, lists, paragraphs, etc. via a DCOM connection where R is the client and Word is the server. There are two packages to do this - rcom and RDCOMClient and both allow you to work at much higher levels of specificity than cutting and pasting HTML or CSV content. You'd have to learn a little about the DCOM API for Word, but there are examples. ~ D. [EMAIL PROTECTED] wrote: | # Dear list, | # I am an R-beginner and | # spent the last days looking for a method to insert tables produced | # with R into a word document. I thought about SPPS: copy a table from | # an SPO-file and paste it into a word document | # (if needed do some formatting with that table). | # Annother idea was, to produce a TEX-file, | # insert it and make it a word-table. | | # I found the following libraries, which seemed to be promising: | # xtable | # prettyR | # R2HTML | # Hmisc | # SciViews / svViews | | | | ### | ## My example: a crosstable (made with CrossTable from lib gmodels | ### | | library(gmodels) | library(xtable) | library(svViews) | | # Data for crosstabulation | set.seed(1) | n <- 200 | sex <- sample(c("f","m"),n,T) | state <- sample(c("AL","AK","CA"),n,T) | | #Create crosstab | ct <- CrossTable(state, sex, expected=TRUE, format="SPSS", digits=1) | ct #display crosstab on screen | | #Trie to produce a html file | xtable(ct) #Error message: No method! | methods(xtable) | | | | #Try to create a rich formatted table and insert it into Word | #with svViws, but only a little part of crosstab it inserted | | docdir <- "r:\\r" | WordOpen(file.path(docdir, "cross.doc")) | viewfile <- view(ct, type = "summary", browse = FALSE) | WordGoto("ctview") | WordInsertFile(viewfile, TRUE) #only a little part of crosstab inserted | WordActivate(async = TRUE) | | | #How could I create the latex-code for the crosstable? | w <- latex(ct) #would that work? | | # I could not test this, because I didn´t install Miktex yet | # (I will do this soon) | | Can someone help me? | | Thanks in advance | Udo | | | -- | Udo Koenig | Clinic for child and adolescent psychiatry | University of Marburg / Germany | | __ | 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. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.7 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHuGsu9p/Jzwa2QP4RAn9xAJ94KmlBA5Yl1hfT4Z0CsmL7s61qpwCfZNhn BMaw4u4FggRWn3QrKg79PAw= =mElZ -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] Transfer Crosstable to Word-Document
On Feb 17, 2008 8:20 AM, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > > On Feb 17, 2008 4:41 AM, Peter Dalgaard <[EMAIL PROTECTED]> wrote: > > > > Gabor Grothendieck wrote: > > > On Feb 16, 2008 5:28 PM, David Scott <[EMAIL PROTECTED]> wrote: > > > > > >> On Sat, 16 Feb 2008, Alan Zaslavsky wrote: > > >> > > >> > > >>> If you want to get nicely formatted tables in Word and are familiar with > > >>> Office tools (I know it's the Evil Empire but some of us work there), I > > >>> suggest that you use Excel for formatting and then insert the table into > > >>> your Word document. IMHO, Excel is much superior to Word for table > > >>> formatting, e.g. modifying number of significant digits, playing around > > >>> with fonts and number formats, etc. And when you have gotten the > > >>> formats > > >>> right you can paste in modified values of the numbers in the table > > >>> without > > >>> having to do the formatting again. Including the table in your Word > > >>> document is easy by cut-paste or creating a live link. > > >>> > > >>> As a user of R under Unix I haven't looked into the facilities for > > >>> writing > > >>> tables to Excel under Windows but there is something there. > > >>> Alternatively > > >>> you can write a fixed-column or tab-delimited file and easily import to > > >>> Excel. > > >>> > > >>> > > >> Production of tables and formatting them in Word is something I have > > >> dealt > > >> with a couple of times recently and it really is important to do > > >> something > > >> smart because of the time taken to individually format tables. > > >> > > >> An approach I used recently was to produce a text table in R and export > > >> it > > >> to Excel as a .csv file which could then be copied as is to Word. Borders > > >> and the like would still have to be formatted individually but not > > >> entries > > >> > > > > > > You could get a border automatically by writing your table out > > > as HTML. Try this using the builtin data frame iris: > > > > > > library(R2HTML) > > > HTML(iris, border = 1, file("clipboard","w"), append=FALSE) > > > > > > Now paste that into Excel and from Excel into Word and you should > > > have a border around it. > > > > > > See ?HTML.data.frame > > > > > > You could alternately generate the HTML yourself giving quite a bit > > > of control. > > > > > Just curious (I don't use Word if I can help it -- even the simplest of > > things drive me up the wall), but can you not import HTML directly in > > Word? OpenOffice seems to do it quite happily with xtable output. > > You can open an HTML file in Word as a new document and it will > be properly formatted and then you could save that document as > a Word document and insert it into your main Word document. > Alternately, you could copy and paste it from the newly created Word > document into your main Word document and that would preserve formatting. Actually you could alternately read the HTML file into Word with formatting preserved using Insert > Object > Create From File (that's in Word 2007; I think the menus are slightly different in earlier versions) and not use the clipboard at all. That's a bit of a nuisance due to the requirement of creating the intermediate file and having to browse to it in Word. Thus pasting it into Excel and then Word is probably still the fastest but this would be a viable alternative and would be superior if you wanted to generate many tables in R at once and then later add them to Word. __ 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] Transfer Crosstable to Word-Document
On Feb 17, 2008 2:49 PM, Udo König <[EMAIL PROTECTED]> wrote: > [...] > Greg: > To the odfWeave package: in [2] I found the sentence "The package is currently > limited to creating text documents using OpenOffice". So it doesn´t seem work > with MS-Word? Udo, I think odfWeave is exactly what you need here. You can also use it with MS-Word via the SUN ODF Plugin for MS Office. It adds the capability to load and save odf docs within MS Office. Get the (free as in beer) plugin from here: http://www.sun.com/software/star/odf_plugin/whats_new.jsp Then write your document in Word, save as ODF, run odfWeave, load the result in Word and save as .doc. HTH, Tobias __ 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] Transfer Crosstable to Word-Document
(2. attempt to post this) (Udo) Quoting Greg Snow <[EMAIL PROTECTED]>: > If your final goal is a word document, then you should look at the odfWeave > package. > At work my primary goal has to be a word document, because: * we have a Windows-XP network with MS-Office software * my boss and my colleagues are not firm with other software (I have to cooperate with them) My idea is to insert simple tables into Word (what I asked for in this thread) and to make more sohisticated tables -like [1]- with latex and include them as a graphic file. I would NOT like to make such a table with MS-Word! I read an introductory Latex script and asked our admin to install the Miktex package on my computer. At home I can fortunately do what I want (Windows, Linux, OpenOffice,...). Greg: To the odfWeave package: in [2] I found the sentence "The package is currently limited to creating text documents using OpenOffice". So it doesn´t seem work with MS-Word? [1] #Taken from: http://biostat.mc.vanderbilt.edu/twiki/pub/Main/StatReport/summary.pdf, p. 28 library(Hmisc) getHdata(pbc) attach(pbc) s5 <- summary(drug ~ bili + albumin + stage + protime + sex + age + spiders, method="reverse", dta=pbc, test=TRUE) options(digits=1) print(s5, npct="both") options(digits=3) w <- latex(s5, size="smaller", npct="both", npct.size="smaller[2]", Nsize="smaller[2]", msdsize="smaller[2]", middle.bold=TRUE, landscape=TRUE) wd <- dvi(w) detach(pbc) [2] R newsletter, Volume 6/4, October 2006, p.3 Udo König Clinic for Child an Adolescent Psychiatry Philipps University of Marburg / Germany __ 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] Transfer Crosstable to Word-Document
On Feb 17, 2008 4:41 AM, Peter Dalgaard <[EMAIL PROTECTED]> wrote: > > Gabor Grothendieck wrote: > > On Feb 16, 2008 5:28 PM, David Scott <[EMAIL PROTECTED]> wrote: > > > >> On Sat, 16 Feb 2008, Alan Zaslavsky wrote: > >> > >> > >>> If you want to get nicely formatted tables in Word and are familiar with > >>> Office tools (I know it's the Evil Empire but some of us work there), I > >>> suggest that you use Excel for formatting and then insert the table into > >>> your Word document. IMHO, Excel is much superior to Word for table > >>> formatting, e.g. modifying number of significant digits, playing around > >>> with fonts and number formats, etc. And when you have gotten the formats > >>> right you can paste in modified values of the numbers in the table without > >>> having to do the formatting again. Including the table in your Word > >>> document is easy by cut-paste or creating a live link. > >>> > >>> As a user of R under Unix I haven't looked into the facilities for writing > >>> tables to Excel under Windows but there is something there. Alternatively > >>> you can write a fixed-column or tab-delimited file and easily import to > >>> Excel. > >>> > >>> > >> Production of tables and formatting them in Word is something I have dealt > >> with a couple of times recently and it really is important to do something > >> smart because of the time taken to individually format tables. > >> > >> An approach I used recently was to produce a text table in R and export it > >> to Excel as a .csv file which could then be copied as is to Word. Borders > >> and the like would still have to be formatted individually but not entries > >> > > > > You could get a border automatically by writing your table out > > as HTML. Try this using the builtin data frame iris: > > > > library(R2HTML) > > HTML(iris, border = 1, file("clipboard","w"), append=FALSE) > > > > Now paste that into Excel and from Excel into Word and you should > > have a border around it. > > > > See ?HTML.data.frame > > > > You could alternately generate the HTML yourself giving quite a bit > > of control. > > > Just curious (I don't use Word if I can help it -- even the simplest of > things drive me up the wall), but can you not import HTML directly in > Word? OpenOffice seems to do it quite happily with xtable output. You can open an HTML file in Word as a new document and it will be properly formatted and then you could save that document as a Word document and insert it into your main Word document. Alternately, you could copy and paste it from the newly created Word document into your main Word document and that would preserve formatting. If you just use the code I posted then if you try to paste that into Word you get the HTML source code rather than a formatted table in Word. Thus its really easier just to paste it into Excel and then into Word as others have mentioned. It might be possible to get it onto the clipboard in a correctly formatted way using: out <- capture.output(HTML(iris, stdout(), border = 1, append = FALSE)) writeClipboard(out, format = whatever) for an appropriate whatever so that it retains its format when pasted into Word. Some experimentation would be required to find an appropriate whatever. It would also be possible to write rcom or RDCOMClient code in R which transferred the document to Word or Excel and copied that new document to the clipboard, all completely automatically, to ensure its in the proper format. __ 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] Transfer Crosstable to Word-Document
Gabor Grothendieck wrote: > On Feb 16, 2008 5:28 PM, David Scott <[EMAIL PROTECTED]> wrote: > >> On Sat, 16 Feb 2008, Alan Zaslavsky wrote: >> >> >>> If you want to get nicely formatted tables in Word and are familiar with >>> Office tools (I know it's the Evil Empire but some of us work there), I >>> suggest that you use Excel for formatting and then insert the table into >>> your Word document. IMHO, Excel is much superior to Word for table >>> formatting, e.g. modifying number of significant digits, playing around >>> with fonts and number formats, etc. And when you have gotten the formats >>> right you can paste in modified values of the numbers in the table without >>> having to do the formatting again. Including the table in your Word >>> document is easy by cut-paste or creating a live link. >>> >>> As a user of R under Unix I haven't looked into the facilities for writing >>> tables to Excel under Windows but there is something there. Alternatively >>> you can write a fixed-column or tab-delimited file and easily import to >>> Excel. >>> >>> >> Production of tables and formatting them in Word is something I have dealt >> with a couple of times recently and it really is important to do something >> smart because of the time taken to individually format tables. >> >> An approach I used recently was to produce a text table in R and export it >> to Excel as a .csv file which could then be copied as is to Word. Borders >> and the like would still have to be formatted individually but not entries >> > > You could get a border automatically by writing your table out > as HTML. Try this using the builtin data frame iris: > > library(R2HTML) > HTML(iris, border = 1, file("clipboard","w"), append=FALSE) > > Now paste that into Excel and from Excel into Word and you should > have a border around it. > > See ?HTML.data.frame > > You could alternately generate the HTML yourself giving quite a bit > of control. > Just curious (I don't use Word if I can help it -- even the simplest of things drive me up the wall), but can you not import HTML directly in Word? OpenOffice seems to do it quite happily with xtable output. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ 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] Transfer Crosstable to Word-Document
If your final goal is a word document, then you should look at the odfWeave package. From: [EMAIL PROTECTED] on behalf of [EMAIL PROTECTED] Sent: Fri 2/15/2008 8:30 AM To: r-help@r-project.org Subject: [R] Transfer Crosstable to Word-Document # Dear list, # I am an R-beginner and # spent the last days looking for a method to insert tables produced # with R into a word document. I thought about SPPS: copy a table from # an SPO-file and paste it into a word document # (if needed do some formatting with that table). # Annother idea was, to produce a TEX-file, # insert it and make it a word-table. # I found the following libraries, which seemed to be promising: # xtable # prettyR # R2HTML # Hmisc # SciViews / svViews ### ## My example: a crosstable (made with CrossTable from lib gmodels ### library(gmodels) library(xtable) library(svViews) # Data for crosstabulation set.seed(1) n <- 200 sex <- sample(c("f","m"),n,T) state <- sample(c("AL","AK","CA"),n,T) #Create crosstab ct <- CrossTable(state, sex, expected=TRUE, format="SPSS", digits=1) ct #display crosstab on screen #Trie to produce a html file xtable(ct) #Error message: No method! methods(xtable) #Try to create a rich formatted table and insert it into Word #with svViws, but only a little part of crosstab it inserted docdir <- "r:\\r" WordOpen(file.path(docdir, "cross.doc")) viewfile <- view(ct, type = "summary", browse = FALSE) WordGoto("ctview") WordInsertFile(viewfile, TRUE) #only a little part of crosstab inserted WordActivate(async = TRUE) #How could I create the latex-code for the crosstable? w <- latex(ct) #would that work? # I could not test this, because I didn´t install Miktex yet # (I will do this soon) Can someone help me? Thanks in advance Udo -- Udo Koenig Clinic for child and adolescent psychiatry University of Marburg / Germany __ 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. [[alternative HTML version deleted]] __ 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] Transfer Crosstable to Word-Document
On Feb 16, 2008 5:28 PM, David Scott <[EMAIL PROTECTED]> wrote: > On Sat, 16 Feb 2008, Alan Zaslavsky wrote: > > > > > If you want to get nicely formatted tables in Word and are familiar with > > Office tools (I know it's the Evil Empire but some of us work there), I > > suggest that you use Excel for formatting and then insert the table into > > your Word document. IMHO, Excel is much superior to Word for table > > formatting, e.g. modifying number of significant digits, playing around > > with fonts and number formats, etc. And when you have gotten the formats > > right you can paste in modified values of the numbers in the table without > > having to do the formatting again. Including the table in your Word > > document is easy by cut-paste or creating a live link. > > > > As a user of R under Unix I haven't looked into the facilities for writing > > tables to Excel under Windows but there is something there. Alternatively > > you can write a fixed-column or tab-delimited file and easily import to > > Excel. > > > > Production of tables and formatting them in Word is something I have dealt > with a couple of times recently and it really is important to do something > smart because of the time taken to individually format tables. > > An approach I used recently was to produce a text table in R and export it > to Excel as a .csv file which could then be copied as is to Word. Borders > and the like would still have to be formatted individually but not entries You could get a border automatically by writing your table out as HTML. Try this using the builtin data frame iris: library(R2HTML) HTML(iris, border = 1, file("clipboard","w"), append=FALSE) Now paste that into Excel and from Excel into Word and you should have a border around it. See ?HTML.data.frame You could alternately generate the HTML yourself giving quite a bit of control. __ 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] Transfer Crosstable to Word-Document
On Sat, 16 Feb 2008, Alan Zaslavsky wrote: > > If you want to get nicely formatted tables in Word and are familiar with > Office tools (I know it's the Evil Empire but some of us work there), I > suggest that you use Excel for formatting and then insert the table into > your Word document. IMHO, Excel is much superior to Word for table > formatting, e.g. modifying number of significant digits, playing around > with fonts and number formats, etc. And when you have gotten the formats > right you can paste in modified values of the numbers in the table without > having to do the formatting again. Including the table in your Word > document is easy by cut-paste or creating a live link. > > As a user of R under Unix I haven't looked into the facilities for writing > tables to Excel under Windows but there is something there. Alternatively > you can write a fixed-column or tab-delimited file and easily import to > Excel. > Production of tables and formatting them in Word is something I have dealt with a couple of times recently and it really is important to do something smart because of the time taken to individually format tables. An approach I used recently was to produce a text table in R and export it to Excel as a .csv file which could then be copied as is to Word. Borders and the like would still have to be formatted individually but not entries in the table (with a minor caveat below). The tables comprised results of test with p-values and confidence intervals etc for various variables. To produce the entries in the table I wrote a small function which pasted bits of output together and formatted numbers exactly using formatC. Often the function produced a number of cells at one time. One difficulty I had was Excel deciding as usual that it knew better than I did what I wanted. So when I had a cell with a p-value in brackets, that was of course a negative number for example. My solution was to prepend a ' character which make Excel treat the following characters literally. Once the table has been put in Word a simple search and replace can remove the ' characters. Overall, I was reasonably happy with the approach I took. If I have a future need I will have some ready-made functions to work from which will make life easier. I will be interested to try some of the other suggestions in this thread. David Scott _ David Scott Department of Statistics, Tamaki Campus The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000 Email: [EMAIL PROTECTED] Graduate Officer, Department of Statistics Director of Consulting, Department of Statistics __ 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] Transfer Crosstable to Word-Document
Hi, thank you very much for your comments and examples, which are very helpful! [I saw that the summary.formula (lib. Hmisc) has an option "cross", which might be useful too...] Alan, I agree with you: at the workplace we have a Windows-XP network with MS-Office, so I have to cope with this; I will test your Excel-suggestion. At home I use Windows-XP with Open Office, but I begin to work with Linux too. Udo Quoting Alan Zaslavsky <[EMAIL PROTECTED]>: > > If you want to get nicely formatted tables in Word and are familiar with > Office tools (I know it's the Evil Empire but some of us work there), I > suggest that you use Excel for formatting and then insert the table into > your Word document. IMHO, Excel is much superior to Word for table > formatting, e.g. modifying number of significant digits, playing around > with fonts and number formats, etc. And when you have gotten the formats > right you can paste in modified values of the numbers in the table without > having to do the formatting again. Including the table in your Word > document is easy by cut-paste or creating a live link. > > As a user of R under Unix I haven't looked into the facilities for writing > tables to Excel under Windows but there is something there. Alternatively > you can write a fixed-column or tab-delimited file and easily import to > Excel. > > __ > 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] Transfer Crosstable to Word-Document
If you want to get nicely formatted tables in Word and are familiar with Office tools (I know it's the Evil Empire but some of us work there), I suggest that you use Excel for formatting and then insert the table into your Word document. IMHO, Excel is much superior to Word for table formatting, e.g. modifying number of significant digits, playing around with fonts and number formats, etc. And when you have gotten the formats right you can paste in modified values of the numbers in the table without having to do the formatting again. Including the table in your Word document is easy by cut-paste or creating a live link. As a user of R under Unix I haven't looked into the facilities for writing tables to Excel under Windows but there is something there. Alternatively you can write a fixed-column or tab-delimited file and easily import to Excel. __ 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] Transfer Crosstable to Word-Document
Here is a partial solution. It still requires some manual intervention. # run this in R data(infert); attach(infert) Lines <- capture.output(CrossTable(education, induced)) ix <- grep(" | ", Lines, fixed = TRUE) writeLines(Lines[ix], "clipboard") Now paste the clipboard into Word, select the table in Word and use Word's text to table command as Don had suggested. (In Excel 2007 its on Insert > Table > Text to Table.) When I tried this it automatically figured out that | is the separator and created the table properly. Note that this depends on the fact that the tabular portion of the output, which is presumably what you want to transfer, has a space-bar-space on every line and no other lines do. There are many arguments to CrossTable and if some of them do not obey that then it will have to modified accordingly for those argument combinations. On Feb 15, 2008 12:31 PM, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > In that case you shouldn't be using CrossTable in the first place. > > Suggest you look into the functions mentioned under See Also in > ?CrossTable or look at the source of CrossTable and modify it for > your purposes. > > > On Fri, Feb 15, 2008 at 11:52 AM, <[EMAIL PROTECTED]> wrote: > > > > Thank you Gabor, > > but with 1. or 2. I don´t get > > a table, which can be changed and formatted using the WORD table functions > > (like changing column width and formatting text in rows). > > > > The result of 1. ist an bitmap and > > the result of 2. an ASCII-Table > > > > A rich formatted (*.rtf) table/object would be better. > > I tried this with the view() (see below). > > Udo > > > > > > > > > > Quoting Gabor Grothendieck <[EMAIL PROTECTED]>: > > > > > Here are 2 ways: > > > > > > 1. Display it on the screen and hit the PrintScreen button. > > > Then paste that into Word and use Word's image editor > > > to crop it and expand or shrink it appropriately. > > > > > > 2. Run this in R: > > > > > > capture.output(CrossTable(...whatever...), file = "clipboard") > > > > > > Paste the clipboard into Word and change the font of the > > > pasted text to Courier or other fixed space font and change its > > > size too if need be. > > > > > > On Fri, Feb 15, 2008 at 10:30 AM, <[EMAIL PROTECTED]> wrote: > > > > # Dear list, > > > > # I am an R-beginner and > > > > # spent the last days looking for a method to insert tables produced > > > > # with R into a word document. I thought about SPPS: copy a table from > > > > # an SPO-file and paste it into a word document > > > > # (if needed do some formatting with that table). > > > > # Annother idea was, to produce a TEX-file, > > > > # insert it and make it a word-table. > > > > > > > > # I found the following libraries, which seemed to be promising: > > > > # xtable > > > > # prettyR > > > > # R2HTML > > > > # Hmisc > > > > # SciViews / svViews > > > > > > > > > > > > > > > > ### > > > > ## My example: a crosstable (made with CrossTable from lib gmodels > > > > ### > > > > > > > > library(gmodels) > > > > library(xtable) > > > > library(svViews) > > > > > > > > # Data for crosstabulation > > > > set.seed(1) > > > > n <- 200 > > > > sex <- sample(c("f","m"),n,T) > > > > state <- sample(c("AL","AK","CA"),n,T) > > > > > > > > #Create crosstab > > > > ct <- CrossTable(state, sex, expected=TRUE, format="SPSS", digits=1) > > > > ct #display crosstab on screen > > > > > > > > #Trie to produce a html file > > > > xtable(ct) #Error message: No method! > > > > methods(xtable) > > > > > > > > > > > > > > > > #Try to create a rich formatted table and insert it into Word > > > > #with svViws, but only a little part of crosstab it inserted > > > > > > > > docdir <- "r:\\r" > > > > WordOpen(file.path(docdir, "cross.doc")) > > > > viewfile <- view(ct, type = "summary", browse = FALSE) > > > > WordGoto("ctview") > > > > WordInsertFile(viewfile, TRUE) #only a little part of crosstab inserted > > > > WordActivate(async = TRUE) > > > > > > > > > > > > #How could I create the latex-code for the crosstable? > > > > w <- latex(ct) #would that work? > > > > > > > > # I could not test this, because I didn´t install Miktex yet > > > > # (I will do this soon) > > > > > > > > Can someone help me? > > > > > > > > Thanks in advance > > > > Udo > > > > > > > > > > > > -- > > > > Udo Koenig > > > > Clinic for child and adolescent psychiatry > > > > University of Marburg / Germany > > > > > > > > __ > > > > 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 > > http
Re: [R] Transfer Crosstable to Word-Document
[EMAIL PROTECTED] wrote: > # Dear list, > # I am an R-beginner and > # spent the last days looking for a method to insert tables produced > # with R into a word document. I thought about SPPS: copy a table from > # an SPO-file and paste it into a word document > # (if needed do some formatting with that table). Hi Udo, Try running the example from delim.table in the prettyR package, then open the file "testdelim.html" in Word, copy and paste one of the tables into your Word document. It works for me in OpenOffice (I don't have Word at home). Jim __ 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] Transfer Crosstable to Word-Document
I usually use the write.table() function (with tab as the delimiter) to write to a text file, then copy/paste into Word, then use Word's convert text to table command. Obviously, if one needs to do this for many, many, tables, the amount of manual manipulation is excessive. That's when products other than Word become better choices. (Framemaker, LaTeX come to mind) -Don At 4:30 PM +0100 2/15/08, [EMAIL PROTECTED] wrote: ># Dear list, ># I am an R-beginner and ># spent the last days looking for a method to insert tables produced ># with R into a word document. I thought about SPPS: copy a table from ># an SPO-file and paste it into a word document ># (if needed do some formatting with that table). ># Annother idea was, to produce a TEX-file, ># insert it and make it a word-table. > ># I found the following libraries, which seemed to be promising: ># xtable ># prettyR ># R2HTML ># Hmisc ># SciViews / svViews > > > >### >## My example: a crosstable (made with CrossTable from lib gmodels >### > >library(gmodels) >library(xtable) >library(svViews) > ># Data for crosstabulation >set.seed(1) >n <- 200 >sex <- sample(c("f","m"),n,T) >state <- sample(c("AL","AK","CA"),n,T) > >#Create crosstab >ct <- CrossTable(state, sex, expected=TRUE, format="SPSS", digits=1) >ct #display crosstab on screen > >#Trie to produce a html file >xtable(ct) #Error message: No method! >methods(xtable) > > > >#Try to create a rich formatted table and insert it into Word >#with svViws, but only a little part of crosstab it inserted > >docdir <- "r:\\r" >WordOpen(file.path(docdir, "cross.doc")) >viewfile <- view(ct, type = "summary", browse = FALSE) >WordGoto("ctview") >WordInsertFile(viewfile, TRUE) #only a little part of crosstab inserted >WordActivate(async = TRUE) > > >#How could I create the latex-code for the crosstable? >w <- latex(ct) #would that work? > ># I could not test this, because I didn´t install Miktex yet ># (I will do this soon) > >Can someone help me? > >Thanks in advance >Udo > > >-- >Udo Koenig >Clinic for child and adolescent psychiatry >University of Marburg / Germany > >__ >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. -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 __ 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] Transfer Crosstable to Word-Document
In that case you shouldn't be using CrossTable in the first place. Suggest you look into the functions mentioned under See Also in ?CrossTable or look at the source of CrossTable and modify it for your purposes. On Fri, Feb 15, 2008 at 11:52 AM, <[EMAIL PROTECTED]> wrote: > > Thank you Gabor, > but with 1. or 2. I don´t get > a table, which can be changed and formatted using the WORD table functions > (like changing column width and formatting text in rows). > > The result of 1. ist an bitmap and > the result of 2. an ASCII-Table > > A rich formatted (*.rtf) table/object would be better. > I tried this with the view() (see below). > Udo > > > > > Quoting Gabor Grothendieck <[EMAIL PROTECTED]>: > > > Here are 2 ways: > > > > 1. Display it on the screen and hit the PrintScreen button. > > Then paste that into Word and use Word's image editor > > to crop it and expand or shrink it appropriately. > > > > 2. Run this in R: > > > > capture.output(CrossTable(...whatever...), file = "clipboard") > > > > Paste the clipboard into Word and change the font of the > > pasted text to Courier or other fixed space font and change its > > size too if need be. > > > > On Fri, Feb 15, 2008 at 10:30 AM, <[EMAIL PROTECTED]> wrote: > > > # Dear list, > > > # I am an R-beginner and > > > # spent the last days looking for a method to insert tables produced > > > # with R into a word document. I thought about SPPS: copy a table from > > > # an SPO-file and paste it into a word document > > > # (if needed do some formatting with that table). > > > # Annother idea was, to produce a TEX-file, > > > # insert it and make it a word-table. > > > > > > # I found the following libraries, which seemed to be promising: > > > # xtable > > > # prettyR > > > # R2HTML > > > # Hmisc > > > # SciViews / svViews > > > > > > > > > > > > ### > > > ## My example: a crosstable (made with CrossTable from lib gmodels > > > ### > > > > > > library(gmodels) > > > library(xtable) > > > library(svViews) > > > > > > # Data for crosstabulation > > > set.seed(1) > > > n <- 200 > > > sex <- sample(c("f","m"),n,T) > > > state <- sample(c("AL","AK","CA"),n,T) > > > > > > #Create crosstab > > > ct <- CrossTable(state, sex, expected=TRUE, format="SPSS", digits=1) > > > ct #display crosstab on screen > > > > > > #Trie to produce a html file > > > xtable(ct) #Error message: No method! > > > methods(xtable) > > > > > > > > > > > > #Try to create a rich formatted table and insert it into Word > > > #with svViws, but only a little part of crosstab it inserted > > > > > > docdir <- "r:\\r" > > > WordOpen(file.path(docdir, "cross.doc")) > > > viewfile <- view(ct, type = "summary", browse = FALSE) > > > WordGoto("ctview") > > > WordInsertFile(viewfile, TRUE) #only a little part of crosstab inserted > > > WordActivate(async = TRUE) > > > > > > > > > #How could I create the latex-code for the crosstable? > > > w <- latex(ct) #would that work? > > > > > > # I could not test this, because I didn´t install Miktex yet > > > # (I will do this soon) > > > > > > Can someone help me? > > > > > > Thanks in advance > > > Udo > > > > > > > > > -- > > > Udo Koenig > > > Clinic for child and adolescent psychiatry > > > University of Marburg / Germany > > > > > > __ > > > 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.
Re: [R] Transfer Crosstable to Word-Document
Udo, CrossTable() knows nothing about the proprietary formats of Word tables. The output is designed for the R console, using a fixed width (monospace) font. The cell boundaries are drawn using standard ASCII characters. There are no plans at present to modify the format of the output to support third party application functionality, though I am considering a future modification to enable LaTeX output to support Sweave functionality. You are of course free to modify the source code for CrossTable() to fit your own requirements, which is the advantage of using an open source platform. Regards, Marc Schwartz [EMAIL PROTECTED] wrote: > Thank you Gabor, > but with 1. or 2. I don´t get > a table, which can be changed and formatted using the WORD table functions > (like changing column width and formatting text in rows). > > The result of 1. ist an bitmap and > the result of 2. an ASCII-Table > > A rich formatted (*.rtf) table/object would be better. > I tried this with the view() (see below). > Udo > > > > Quoting Gabor Grothendieck<[EMAIL PROTECTED]>: > >> Here are 2 ways: >> >> 1. Display it on the screen and hit the PrintScreen button. >> Then paste that into Word and use Word's image editor >> to crop it and expand or shrink it appropriately. >> >> 2. Run this in R: >> >> capture.output(CrossTable(...whatever...), file = "clipboard") >> >> Paste the clipboard into Word and change the font of the >> pasted text to Courier or other fixed space font and change its >> size too if need be. >> >> On Fri, Feb 15, 2008 at 10:30 AM,<[EMAIL PROTECTED]> wrote: >>> # Dear list, >>> # I am an R-beginner and >>> # spent the last days looking for a method to insert tables produced >>> # with R into a word document. I thought about SPPS: copy a table from >>> # an SPO-file and paste it into a word document >>> # (if needed do some formatting with that table). >>> # Annother idea was, to produce a TEX-file, >>> # insert it and make it a word-table. >>> >>> # I found the following libraries, which seemed to be promising: >>> # xtable >>> # prettyR >>> # R2HTML >>> # Hmisc >>> # SciViews / svViews >>> >>> >>> >>> ### >>> ## My example: a crosstable (made with CrossTable from lib gmodels >>> ### >>> >>> library(gmodels) >>> library(xtable) >>> library(svViews) >>> >>> # Data for crosstabulation >>> set.seed(1) >>> n<- 200 >>> sex<- sample(c("f","m"),n,T) >>> state<- sample(c("AL","AK","CA"),n,T) >>> >>> #Create crosstab >>> ct<- CrossTable(state, sex, expected=TRUE, format="SPSS", digits=1) >>> ct #display crosstab on screen >>> >>> #Trie to produce a html file >>> xtable(ct) #Error message: No method! >>> methods(xtable) >>> >>> >>> >>> #Try to create a rich formatted table and insert it into Word >>> #with svViws, but only a little part of crosstab it inserted >>> >>> docdir<- "r:\\r" >>> WordOpen(file.path(docdir, "cross.doc")) >>> viewfile<- view(ct, type = "summary", browse = FALSE) >>> WordGoto("ctview") >>> WordInsertFile(viewfile, TRUE) #only a little part of crosstab inserted >>> WordActivate(async = TRUE) >>> >>> >>> #How could I create the latex-code for the crosstable? >>> w<- latex(ct) #would that work? >>> >>> # I could not test this, because I didn´t install Miktex yet >>> # (I will do this soon) >>> >>> Can someone help me? >>> >>> Thanks in advance >>> Udo >>> __ 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] Transfer Crosstable to Word-Document
Thank you Gabor, but with 1. or 2. I don´t get a table, which can be changed and formatted using the WORD table functions (like changing column width and formatting text in rows). The result of 1. ist an bitmap and the result of 2. an ASCII-Table A rich formatted (*.rtf) table/object would be better. I tried this with the view() (see below). Udo Quoting Gabor Grothendieck <[EMAIL PROTECTED]>: > Here are 2 ways: > > 1. Display it on the screen and hit the PrintScreen button. > Then paste that into Word and use Word's image editor > to crop it and expand or shrink it appropriately. > > 2. Run this in R: > > capture.output(CrossTable(...whatever...), file = "clipboard") > > Paste the clipboard into Word and change the font of the > pasted text to Courier or other fixed space font and change its > size too if need be. > > On Fri, Feb 15, 2008 at 10:30 AM, <[EMAIL PROTECTED]> wrote: > > # Dear list, > > # I am an R-beginner and > > # spent the last days looking for a method to insert tables produced > > # with R into a word document. I thought about SPPS: copy a table from > > # an SPO-file and paste it into a word document > > # (if needed do some formatting with that table). > > # Annother idea was, to produce a TEX-file, > > # insert it and make it a word-table. > > > > # I found the following libraries, which seemed to be promising: > > # xtable > > # prettyR > > # R2HTML > > # Hmisc > > # SciViews / svViews > > > > > > > > ### > > ## My example: a crosstable (made with CrossTable from lib gmodels > > ### > > > > library(gmodels) > > library(xtable) > > library(svViews) > > > > # Data for crosstabulation > > set.seed(1) > > n <- 200 > > sex <- sample(c("f","m"),n,T) > > state <- sample(c("AL","AK","CA"),n,T) > > > > #Create crosstab > > ct <- CrossTable(state, sex, expected=TRUE, format="SPSS", digits=1) > > ct #display crosstab on screen > > > > #Trie to produce a html file > > xtable(ct) #Error message: No method! > > methods(xtable) > > > > > > > > #Try to create a rich formatted table and insert it into Word > > #with svViws, but only a little part of crosstab it inserted > > > > docdir <- "r:\\r" > > WordOpen(file.path(docdir, "cross.doc")) > > viewfile <- view(ct, type = "summary", browse = FALSE) > > WordGoto("ctview") > > WordInsertFile(viewfile, TRUE) #only a little part of crosstab inserted > > WordActivate(async = TRUE) > > > > > > #How could I create the latex-code for the crosstable? > > w <- latex(ct) #would that work? > > > > # I could not test this, because I didn´t install Miktex yet > > # (I will do this soon) > > > > Can someone help me? > > > > Thanks in advance > > Udo > > > > > > -- > > Udo Koenig > > Clinic for child and adolescent psychiatry > > University of Marburg / Germany > > > > __ > > 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] Transfer Crosstable to Word-Document
Here are 2 ways: 1. Display it on the screen and hit the PrintScreen button. Then paste that into Word and use Word's image editor to crop it and expand or shrink it appropriately. 2. Run this in R: capture.output(CrossTable(...whatever...), file = "clipboard") Paste the clipboard into Word and change the font of the pasted text to Courier or other fixed space font and change its size too if need be. On Fri, Feb 15, 2008 at 10:30 AM, <[EMAIL PROTECTED]> wrote: > # Dear list, > # I am an R-beginner and > # spent the last days looking for a method to insert tables produced > # with R into a word document. I thought about SPPS: copy a table from > # an SPO-file and paste it into a word document > # (if needed do some formatting with that table). > # Annother idea was, to produce a TEX-file, > # insert it and make it a word-table. > > # I found the following libraries, which seemed to be promising: > # xtable > # prettyR > # R2HTML > # Hmisc > # SciViews / svViews > > > > ### > ## My example: a crosstable (made with CrossTable from lib gmodels > ### > > library(gmodels) > library(xtable) > library(svViews) > > # Data for crosstabulation > set.seed(1) > n <- 200 > sex <- sample(c("f","m"),n,T) > state <- sample(c("AL","AK","CA"),n,T) > > #Create crosstab > ct <- CrossTable(state, sex, expected=TRUE, format="SPSS", digits=1) > ct #display crosstab on screen > > #Trie to produce a html file > xtable(ct) #Error message: No method! > methods(xtable) > > > > #Try to create a rich formatted table and insert it into Word > #with svViws, but only a little part of crosstab it inserted > > docdir <- "r:\\r" > WordOpen(file.path(docdir, "cross.doc")) > viewfile <- view(ct, type = "summary", browse = FALSE) > WordGoto("ctview") > WordInsertFile(viewfile, TRUE) #only a little part of crosstab inserted > WordActivate(async = TRUE) > > > #How could I create the latex-code for the crosstable? > w <- latex(ct) #would that work? > > # I could not test this, because I didn´t install Miktex yet > # (I will do this soon) > > Can someone help me? > > Thanks in advance > Udo > > > -- > Udo Koenig > Clinic for child and adolescent psychiatry > University of Marburg / Germany > > __ > 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] Transfer Crosstable to Word-Document (2. attempt)
# Dear list, # I am an R-beginner and # spent the last days looking for a method to insert tables produced # with R into a word document. I thought about SPPS: copy a table from # an SPO-file and paste it into a word document # (if needed do some formatting with that table). # Annother idea was, to produce a TEX-file, # insert it and make it a word-table. # I found the following libraries, which seemed to be promising: # xtable # prettyR # R2HTML # Hmisc # SciViews / svViews ### ## My example: a crosstable (made with CrossTable from lib gmodels ### library(gmodels) library(xtable) library(svViews) # Data for crosstabulation set.seed(1) n <- 200 sex <- sample(c("f","m"),n,T) state <- sample(c("AL","AK","CA"),n,T) #Create crosstab ct <- CrossTable(state, sex, expected=TRUE, format="SPSS", digits=1) ct #display crosstab on screen #Trie to produce a html file xtable(ct) #Error message: No method! methods(xtable) #Try to create a rich formatted table and insert it into Word #with svViws, but only a little part of crosstab it inserted docdir <- "r:\\r" WordOpen(file.path(docdir, "cross.doc")) viewfile <- view(ct, type = "summary", browse = FALSE) WordGoto("ctview") WordInsertFile(viewfile, TRUE) #only a little part of crosstab inserted WordActivate(async = TRUE) #How could I create the latex-code for the crosstable? w <- latex(ct) #would that work? # I could not test this, because I didn´t install Miktex yet # (I will do this soon) Can someone help me? Thanks in advance Udo -- Udo Koenig Clinic for child and adolescent psychiatry University of Marburg / Germany __ 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] Transfer Crosstable to Word-Document
# Dear list, # I am an R-beginner and # spent the last days looking for a method to insert tables produced # with R into a word document. I thought about SPPS: copy a table from # an SPO-file and paste it into a word document # (if needed do some formatting with that table). # Annother idea was, to produce a TEX-file, # insert it and make it a word-table. # I found the following libraries, which seemed to be promising: # xtable # prettyR # R2HTML # Hmisc # SciViews / svViews ### ## My example: a crosstable (made with CrossTable from lib gmodels ### library(gmodels) library(xtable) library(svViews) # Data for crosstabulation set.seed(1) n <- 200 sex <- sample(c("f","m"),n,T) state <- sample(c("AL","AK","CA"),n,T) #Create crosstab ct <- CrossTable(state, sex, expected=TRUE, format="SPSS", digits=1) ct #display crosstab on screen #Trie to produce a html file xtable(ct) #Error message: No method! methods(xtable) #Try to create a rich formatted table and insert it into Word #with svViws, but only a little part of crosstab it inserted docdir <- "r:\\r" WordOpen(file.path(docdir, "cross.doc")) viewfile <- view(ct, type = "summary", browse = FALSE) WordGoto("ctview") WordInsertFile(viewfile, TRUE) #only a little part of crosstab inserted WordActivate(async = TRUE) #How could I create the latex-code for the crosstable? w <- latex(ct) #would that work? # I could not test this, because I didn´t install Miktex yet # (I will do this soon) Can someone help me? Thanks in advance Udo -- Udo Koenig Clinic for child and adolescent psychiatry University of Marburg / Germany __ 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.