R-users At the moment I am teaching a course on the use of R for data analysis. Part of course requirements involves the transfer of results from R to something that resembles the APA (American Psychological Associations) type tables to MS Word. Until now I have used the HTML function in the R2HTML library, with a call like this: HTML(summary(model1), file("clipboard", "w"), digits=4) Where "model1" is an object containing results from a linear model (function lm ()). I have to add that I do not remember where I got the digits argument from. The main point is that the output is transferred to Excel as the first step where the output can be deleted and shuffled in order to produce a correctly formatted table according to APA standards which then is transferred to MS Word with a copy and paste operation. The problem is simply that what is tranferred to Excel varies with what you throw at the HTML function. Nothing is rounded of with an lm() model. With a function like sd () I seem to consistently get 2 decimal points transferred, less than what I want, while there are variations in respect to the number of decimals when I transfer the result on the summary () using a frame as the argument. The optimal thing for me (and the students) would be to consistently have all the decimals tranferred to Excel, any rounding to could be done there before the transfer of the table to MS Word. Alternatively, that something like the argument digits=x works in a consistent manner with at least most objects. So: What do I tell my students on what to do using R2HTML in order to obtain consistent results? Alternativly: are there other alternatives I and my students could use for the transfer of results from R via Excel to MS Word? I really would appreciate some suggestions. Tom
Try using gsubfn from the gsubfn package: # test data based on builtin iris data set mod <- summary(lm(Sepal.Length ~., iris)) library(R2HTML); library(gsubfn) HTML(mod, file = textConnection("out", "w")) out2 <- gsubfn("[0-9]+[.][0-9]+", ~ round(as.numeric(x), 2), out) cat(paste(out2, "\n"), "\n", file = "myfile.html") Now read myfile.html into Word (or into Excel and then into Word). On Fri, Oct 24, 2008 at 3:30 PM, Tom Backer Johnsen <backer at psych.uib.no> wrote:> R-users > > At the moment I am teaching a course on the use of R for data analysis. > Part of course requirements involves the transfer of results from R to > something that resembles the APA (American Psychological Associations) type > tables to MS Word. Until now I have used the HTML function in the R2HTML > library, with a call like this: > > HTML(summary(model1), file("clipboard", "w"), digits=4) > > Where "model1" is an object containing results from a linear model (function > lm ()). I have to add that I do not remember where I got the digits > argument from. The main point is that the output is transferred to Excel as > the first step where the output can be deleted and shuffled in order to > produce a correctly formatted table according to APA standards which then is > transferred to MS Word with a copy and paste operation. > > The problem is simply that what is tranferred to Excel varies with what you > throw at the HTML function. Nothing is rounded of with an lm() model. With > a function like sd () I seem to consistently get 2 decimal points > transferred, less than what I want, while there are variations in respect to > the number of decimals when I transfer the result on the summary () using a > frame as the argument. > > The optimal thing for me (and the students) would be to consistently have > all the decimals tranferred to Excel, any rounding to could be done there > before the transfer of the table to MS Word. Alternatively, that something > like the argument digits=x works in a consistent manner with at least most > objects. > > So: > > What do I tell my students on what to do using R2HTML in order to obtain > consistent results? > > Alternativly: are there other alternatives I and my students could use for > the transfer of results from R via Excel to MS Word? > > I really would appreciate some suggestions. > > Tom > > ______________________________________________ > R-help at 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. >
You may want to try the odfWeave package. It uses openoffice which can read and write MSWord documents. This is an alternative to the HTML > Excel > Word route. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Tom Backer Johnsen > Sent: Friday, October 24, 2008 1:31 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Transferring results from R to MS Word > > R-users > > At the moment I am teaching a course on the use of R for data analysis. > Part of course requirements involves the transfer of results from R > to > something that resembles the APA (American Psychological Associations) > type tables to MS Word. Until now I have used the HTML function in the > R2HTML library, with a call like this: > > HTML(summary(model1), file("clipboard", "w"), digits=4) > > Where "model1" is an object containing results from a linear model > (function lm ()). I have to add that I do not remember where I got the > digits argument from. The main point is that the output is transferred > to Excel as the first step where the output can be deleted and shuffled > in order to produce a correctly formatted table according to APA > standards which then is transferred to MS Word with a copy and paste > operation. > > The problem is simply that what is tranferred to Excel varies with what > you throw at the HTML function. Nothing is rounded of with an lm() > model. With a function like sd () I seem to consistently get 2 decimal > points transferred, less than what I want, while there are variations > in > respect to the number of decimals when I transfer the result on the > summary () using a frame as the argument. > > The optimal thing for me (and the students) would be to consistently > have all the decimals tranferred to Excel, any rounding to could be > done > there before the transfer of the table to MS Word. Alternatively, that > something like the argument digits=x works in a consistent manner with > at least most objects. > > So: > > What do I tell my students on what to do using R2HTML in order to > obtain > consistent results? > > Alternativly: are there other alternatives I and my students could use > for the transfer of results from R via Excel to MS Word? > > I really would appreciate some suggestions. > > Tom > > ______________________________________________ > R-help at 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.
Greg Snow wrote:> You may want to try the odfWeave package. It uses openoffice which can read and write MSWord documents. This is an alternative to the HTML > Excel > Word route.Now that is an interesting alternative. Not for this term though, to get the students to learn R and at the same time to change word processor would be far from optimal. Tom> > -- > Gregory (Greg) L. Snow Ph.D. > Statistical Data Center > Intermountain Healthcare > greg.snow at imail.org > 801.408.8111 > > >> -----Original Message----- >> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- >> project.org] On Behalf Of Tom Backer Johnsen >> Sent: Friday, October 24, 2008 1:31 PM >> To: r-help at stat.math.ethz.ch >> Subject: [R] Transferring results from R to MS Word >> >> R-users >> >> At the moment I am teaching a course on the use of R for data analysis. >> Part of course requirements involves the transfer of results from R >> to >> something that resembles the APA (American Psychological Associations) >> type tables to MS Word. Until now I have used the HTML function in the >> R2HTML library, with a call like this: >> >> HTML(summary(model1), file("clipboard", "w"), digits=4) >> >> Where "model1" is an object containing results from a linear model >> (function lm ()). I have to add that I do not remember where I got the >> digits argument from. The main point is that the output is transferred >> to Excel as the first step where the output can be deleted and shuffled >> in order to produce a correctly formatted table according to APA >> standards which then is transferred to MS Word with a copy and paste >> operation. >> >> The problem is simply that what is tranferred to Excel varies with what >> you throw at the HTML function. Nothing is rounded of with an lm() >> model. With a function like sd () I seem to consistently get 2 decimal >> points transferred, less than what I want, while there are variations >> in >> respect to the number of decimals when I transfer the result on the >> summary () using a frame as the argument. >> >> The optimal thing for me (and the students) would be to consistently >> have all the decimals tranferred to Excel, any rounding to could be >> done >> there before the transfer of the table to MS Word. Alternatively, that >> something like the argument digits=x works in a consistent manner with >> at least most objects. >> >> So: >> >> What do I tell my students on what to do using R2HTML in order to >> obtain >> consistent results? >> >> Alternativly: are there other alternatives I and my students could use >> for the transfer of results from R via Excel to MS Word? >> >> I really would appreciate some suggestions. >> >> Tom >> >> ______________________________________________ >> R-help at 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.-- +----------------------------------------------------------------+ | Tom Backer Johnsen, Psychometrics Unit, Faculty of Psychology | | University of Bergen, Christies gt. 12, N-5015 Bergen, NORWAY | | Tel : +47-5558-9185 Fax : +47-5558-9879 | | Email : backer at psych.uib.no URL : http://www.galton.uib.no/ | +----------------------------------------------------------------+
Jasim Al-Ajmi wrote:> Dear Tom > I am a new user of R. My problem is how to read excel data files. > How can I read a file called stock in R. What statement I should use? > Thanks for your help.Thye simplest is to save your file as a .CSV file. This is a "plain text" file where the elements are separated with semicolons or commas. The names of the variables (columns) should be in the first row of the sheet. Look in the documentation for read.table (there are other alternatives as well). Call read.table naming your file (or use file.choose()) setting header=T, sep="" to whatever seperates the values in your file, and na.strings = "" to whatever you identify your missing values with. Tom> Best regards > Jasim > On Fri, Oct 24, 2008 at 10:30 PM, Tom Backer Johnsen > <backer at psych.uib.no <mailto:backer at psych.uib.no>> wrote: > > R-users > > At the moment I am teaching a course on the use of R for data > analysis. Part of course requirements involves the transfer of > results from R to something that resembles the APA (American > Psychological Associations) type tables to MS Word. Until now I > have used the HTML function in the R2HTML library, with a call like > this: > > HTML(summary(model1), file("clipboard", "w"), digits=4) > > Where "model1" is an object containing results from a linear model > (function lm ()). I have to add that I do not remember where I got > the digits argument from. The main point is that the output is > transferred to Excel as the first step where the output can be > deleted and shuffled in order to produce a correctly formatted table > according to APA standards which then is transferred to MS Word with > a copy and paste operation. > > The problem is simply that what is tranferred to Excel varies with > what you throw at the HTML function. Nothing is rounded of with an > lm() model. With a function like sd () I seem to consistently get 2 > decimal points transferred, less than what I want, while there are > variations in respect to the number of decimals when I transfer the > result on the summary () using a frame as the argument. > > The optimal thing for me (and the students) would be to consistently > have all the decimals tranferred to Excel, any rounding to could be > done there before the transfer of the table to MS Word. > Alternatively, that something like the argument digits=x works in a > consistent manner with at least most objects. > > So: > > What do I tell my students on what to do using R2HTML in order to > obtain consistent results? > > Alternativly: are there other alternatives I and my students could > use for the transfer of results from R via Excel to MS Word? > > I really would appreciate some suggestions. > > Tom > > ______________________________________________ > R-help at r-project.org <mailto:R-help at 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 > <http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > >-- +----------------------------------------------------------------+ | Tom Backer Johnsen, Psychometrics Unit, Faculty of Psychology | | University of Bergen, Christies gt. 12, N-5015 Bergen, NORWAY | | Tel : +47-5558-9185 Fax : +47-5558-9879 | | Email : backer at psych.uib.no URL : http://www.galton.uib.no/ | +----------------------------------------------------------------+
On Sat, Oct 25, 2008 at 9:05 PM, Tom Backer Johnsen <backer at psych.uib.no> wrote:>> I am a new user of R. My problem is how to read excel data files. >> How can I read a file called stock in R. What statement I should use? >It could help to start learning R with a GUI like Rcmdr. Among other features, it supports importing Excel and CSV files. Liviu
Liviu Andronic wrote:> On Sat, Oct 25, 2008 at 9:05 PM, Tom Backer Johnsen <backer at psych.uib.no> wrote: >>> I am a new user of R. My problem is how to read excel data files. >>> How can I read a file called stock in R. What statement I should use? > It could help to start learning R with a GUI like Rcmdr. Among other > features, it supports importing Excel and CSV files. > LiviuThat is a good alternative. Tom -- +----------------------------------------------------------------+ | Tom Backer Johnsen, Psychometrics Unit, Faculty of Psychology | | University of Bergen, Christies gt. 12, N-5015 Bergen, NORWAY | | Tel : +47-5558-9185 Fax : +47-5558-9879 | | Email : backer at psych.uib.no URL : http://www.galton.uib.no/ | +----------------------------------------------------------------+
Frank E Harrell Jr wrote:> Tom Backer Johnsen wrote: >> Frank E Harrell Jr wrote: >>> Tom Backer Johnsen wrote: >>> >>> I hadn't thought of the 'different random sample' approach. That's >>> neat. >>> Frank >> >> Yes, I am quite proud of that. The program that does the sampling and >> mailing is called "Distras". > > Is that problem part of an open source project?That is my intention. Currently the program is written in Delphi (version 7), but it should be relatively easy to transfer it into a version that can be compiled with an open source Pascal compiler. Tom
To reply to myself, for anything that can be coerced into a table (matrices, vectors) the best solution seems to to use the write.table () function to write a .csv file, which is easily opened with a spreadsheet. The alternative is to use the HTML2clip () function (or the HTML function) in the R2HTML library and then paste the clipboard into Excel. That alternative seems to be OK for objects as returned by the lm () function, but little else. Among other things, the function is extremely heavyhanded in respect to rounding. To see what I mean, try HTML2clip (mean(attitude)). So, are there any other alternatives? Tom
Seems there is a bug in one of the HTML methods in that digitseither does not get passed or used in certain cases. It does seem that the HTML.data.frame method is not affected so this would be a workaround: HTML2clip(as.data.frame(mean(attitude)), digits = 10) On Sun, Oct 26, 2008 at 9:58 AM, Tom Backer Johnsen <backer at psych.uib.no> wrote:> To reply to myself, for anything that can be coerced into a table (matrices, > vectors) the best solution seems to to use the write.table () function to > write a .csv file, which is easily opened with a spreadsheet. > > The alternative is to use the HTML2clip () function (or the HTML function) > in the R2HTML library and then paste the clipboard into Excel. That > alternative seems to be OK for objects as returned by the lm () function, > but little else. Among other things, the function is extremely heavyhanded > in respect to rounding. To see what I mean, try HTML2clip (mean(attitude)). > > So, are there any other alternatives? > > Tom > > ______________________________________________ > R-help at 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. >
Frank E Harrell Jr wrote:> Tom Backer Johnsen wrote: >> Frank E Harrell Jr wrote: >>> Tom Backer Johnsen wrote: >>>> Frank E Harrell Jr wrote: >>>>> Tom Backer Johnsen wrote: >>>>> >>>>> I hadn't thought of the 'different random sample' approach. That's >>>>> neat. >>>>> Frank >>>> >>>> Yes, I am quite proud of that. The program that does the sampling >>>> and mailing is called "Distras". >>> >>> Is that problem part of an open source project? >> >> >> That is my intention. Currently the program is written in Delphi >> (version 7), but it should be relatively easy to transfer it into a >> version that can be compiled with an open source Pascal compiler. >> > > I hope you'll keep the community posted on that. If you ever have a > need for a function in R for linux that makes e-mailing easy, I have one.Now, that is interesting. I have not thought abut mailing from R. The main reason for writing the program in Delphi was that I had the compiler already and that is simple to program something that could mail. Having a copy of a mailing function for Linux would be useful in any case, so my response would simply be: Yes please. Would that function work with Ubuntu?> > One issue I need to face is that for project assignments involving more > comprehensive analyses of datasets there are many right answers so > automatic checking of results is difficult.Yes, that would be tricky. The problems my students get are quite simpleminded. In any case, the checking is not automatic, I still have to compare the answers from the students with my solution "manually". Tom> > Frank > >> Tom >> >> > >-- +----------------------------------------------------------------+ | Tom Backer Johnsen, Psychometrics Unit, Faculty of Psychology | | University of Bergen, Christies gt. 12, N-5015 Bergen, NORWAY | | Tel : +47-5558-9185 Fax : +47-5558-9879 | | Email : backer at psych.uib.no URL : http://www.galton.uib.no/ | +----------------------------------------------------------------+
Gabor Grothendieck wrote:> Seems there is a bug in one of the HTML methods in that digits> either does not get passed or used in certain cases. It does seem > that the HTML.data.frame method is not affected so this would > be a workaround: > > HTML2clip(as.data.frame(mean(attitude)), digits = 10)Ah. That is really useful. Thanks. However, it would be nice if the bug could be fixed in some way or another. I may be wrong, but I think that I have used the HTML function before with less problems. I suspect that the bug is a relatively recent one. Tom> > > On Sun, Oct 26, 2008 at 9:58 AM, Tom Backer Johnsen <backer at psych.uib.no> wrote: >> To reply to myself, for anything that can be coerced into a table (matrices, >> vectors) the best solution seems to to use the write.table () function to >> write a .csv file, which is easily opened with a spreadsheet. >> >> The alternative is to use the HTML2clip () function (or the HTML function) >> in the R2HTML library and then paste the clipboard into Excel. That >> alternative seems to be OK for objects as returned by the lm () function, >> but little else. Among other things, the function is extremely heavyhanded >> in respect to rounding. To see what I mean, try HTML2clip (mean(attitude)). >> >> So, are there any other alternatives? >> >> Tom >> >> ______________________________________________ >> R-help at 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. >>-- +----------------------------------------------------------------+ | Tom Backer Johnsen, Psychometrics Unit, Faculty of Psychology | | University of Bergen, Christies gt. 12, N-5015 Bergen, NORWAY | | Tel : +47-5558-9185 Fax : +47-5558-9879 | | Email : backer at psych.uib.no URL : http://www.galton.uib.no/ | +----------------------------------------------------------------+
I have sent an email to the maintainer about it. On Sun, Oct 26, 2008 at 10:51 AM, Tom Backer Johnsen <backer at psych.uib.no> wrote:> Gabor Grothendieck wrote: >> >> Seems there is a bug in one of the HTML methods in that digits>> either does not get passed or used in certain cases. It does seem >> that the HTML.data.frame method is not affected so this would >> be a workaround: >> >> HTML2clip(as.data.frame(mean(attitude)), digits = 10) > > Ah. That is really useful. Thanks. However, it would be nice if the bug > could be fixed in some way or another. I may be wrong, but I think that I > have used the HTML function before with less problems. I suspect that the > bug is a relatively recent one. > > Tom >> >> >> On Sun, Oct 26, 2008 at 9:58 AM, Tom Backer Johnsen <backer at psych.uib.no> >> wrote: >>> >>> To reply to myself, for anything that can be coerced into a table >>> (matrices, >>> vectors) the best solution seems to to use the write.table () function to >>> write a .csv file, which is easily opened with a spreadsheet. >>> >>> The alternative is to use the HTML2clip () function (or the HTML >>> function) >>> in the R2HTML library and then paste the clipboard into Excel. That >>> alternative seems to be OK for objects as returned by the lm () function, >>> but little else. Among other things, the function is extremely >>> heavyhanded >>> in respect to rounding. To see what I mean, try HTML2clip >>> (mean(attitude)). >>> >>> So, are there any other alternatives? >>> >>> Tom >>> >>> ______________________________________________ >>> R-help at 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. >>> > > > -- > +----------------------------------------------------------------+ > | Tom Backer Johnsen, Psychometrics Unit, Faculty of Psychology | > | University of Bergen, Christies gt. 12, N-5015 Bergen, NORWAY | > | Tel : +47-5558-9185 Fax : +47-5558-9879 | > | Email : backer at psych.uib.no URL : http://www.galton.uib.no/ | > +----------------------------------------------------------------+ >
Gabor Grothendieck wrote:> I have sent an email to the maintainer about it.Thanks! Tom
Hans-Peter Suter wrote:> what about: ?write.xls from my xlsReadWrite package?Sorry, I did not even think to look for something along the lines of what the name of the package suggests. I'll have a look at it! Tom
Felipe Carrillo wrote:> Are you still can't get the data into R? I sent you this -mail last week, did you read it?Yes I did read it, and I have installed the package and looked at the documentation. What I (after an admittently superficial inspection due to limited available time this weekend, the choir I am a member of had a concert yesterday on a monumental mass by Gounod) do not at the moment see is what the advantage of these functions are over standard read.table () and write.table (). I suppose I need to have another look. Using write.table () or similar things has at least two disadvantages as far as I can see. One is that it only works on objects which can be coerced into a table or frame. With other types of objects like summary(lm(formula)) you get an error message. Secondly, you end up with one file (or worksheet) for each thing you want to transfer, which may easily be a mess or confusing (or both). That is why I would prefer something along the lines of HTML, which means that several things may be pasted into the same worksheet, based on a "keep things together that belong together" kind of attitude. So, if you want one table combining means, standard deviations, and variable intercorrelations you do not want things in three different sheets or files, you want them in the same worksheet to begin with. However, at the moment it seems that there are bugs in the R2HTML package, hopefully they will be eliminated in the near future. There are also some parts of the documentation that I do not understand. The list of functions includes things like HTML.lm, as far as I can see are invisible, both in respect to documentation and usage. Tom
Tom Backer Johnsen <backer <at> psych.uib.no> writes:> There > are also some parts of the documentation that I do not understand. The > list of functions includes things like HTML.lm, as far as I can see are > invisible, both in respect to documentation and usage.This might be relic of a function written by my some year ago, which were part of the distribution for some time, but probably removed later. Dieter
Dieter Menne wrote:> Tom Backer Johnsen <backer <at> psych.uib.no> writes: > >> There >> are also some parts of the documentation that I do not understand. The >> list of functions includes things like HTML.lm, as far as I can see are >> invisible, both in respect to documentation and usage. > > This might be relic of a function written by my some year ago, which were part > of the distribution for some time, but probably removed later.Hmm. If that is true, that is not very promising. It could indicate that the maintenace of the package might be patchy. Tom
John Kane wrote:> --- On Mon, 10/27/08, Tom Backer Johnsen <backer at psych.uib.no> wrote: > > > From: Tom Backer Johnsen <backer at psych.uib.no> > > Subject: Re: [R] Transferring results from R to MS Word > > To: "Greg Snow" <Greg.Snow at imail.org> > > Cc: "r-help at stat.math.ethz.ch" <r-help at stat.math.ethz.ch> > > Received: Monday, October 27, 2008, 5:44 PM > > Greg Snow wrote: > > > Any timing is of course your decision, but my > > observation (being one of my company's test cases for > > updating office) is that transitioning from MSWord 2003 to > > OpenOffice Writer will be less work/stress than > > transitioning from MSWord 2003 to MSWord 2007. > > > > That agrees with my own observation, I have Office 2007 > > installed and > > often have to hunt around for things. However, I looked at > > OpenOffice > > some time ago, and one of the impressions that remains is > > that it took a > > long time to load. I may be wrong about that. > > > > Tom > > I believe that OpenOffice.org has been addressing this problem but it seems to be very idiosycratic. I have found that OOo 2.3.1 and 2.4.0 seem to load faster than MS Word 2007 on the same machine. In fact I have never had any of OOo 2.x versions take more than roughly 5 seconds to load on a XP with 1 GB memory. Others report quite long loading times. > > ______________________________________________ > R-help at 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.Hello, I have found that Open Office does not accept imbedded postscript files, which is my output format of choice, when using R for plotting, et. al.. Grudgingly, I have to admit that MS Word does accept postscript files. So, when presentation has to be perfect, I use Latex. Will Open Office ever accept postscript? John