[Rd] Example in pdf() help file (PR#8083)
The example in the help file for pdf() plots the characters outside the plotting area in this for loop: for(i in c(32:255)) { x <- i y <- i points(x, y, pch=i) } The following loop seems to be working as intended for(i in c(32:255)) { x <- (i-31)%%16 y <- (i-31)%/%16 points(x, y, pch=i) } As an extra observation, with code page ISOLatin2, the pdf-file fails to open in Ghostview 4.7 using ghostscript 8.51. Error message below. In Acrobat Reader 7.0 it opens without problems. It is quite possible that it is the settings on my computer that causes the error, but I include the dump of the error message, just in case anybody was interested Best regards Erik Jørgensen Danish Institute of Agricultural Sciences --please do not edit the information below-- Version: platform = i386-pc-mingw32 arch = i386 os = mingw32 system = i386, mingw32 status = major = 2 minor = 1.1 year = 2005 month = 06 day = 20 language = R Windows XP Professional (build 2600) Service Pack 2.0 Locale: LC_COLLATE=Danish_Denmark.1252;LC_CTYPE=Danish_Denmark.1252;LC_MONETARY=Danish_Denmark.1252;LC_NUMERIC=C;LC_TIME=Danish_Denmark.1252 Search Path: .GlobalEnv, package:lattice, package:methods, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, Autoloads, package:base --- GSview 4.7 2005-03-26 AFPL Ghostscript 8.51 (2005-04-18) Copyright (C) 2005 artofcode LLC, Benicia, CA. All rights reserved. This software comes with NO WARRANTY: see the file PUBLIC for details. Scanning PDF file %GSVIEW_PDF_PAGES: 1 1 Displaying PDF page 1 %GSVIEW_PDF_PAGE: 1 %GSVIEW_PDF_MEDIA: [0 0 432 432] %GSVIEW_PDF_ROTATE: 0 Loading NimbusSanL-Regu font from c:\gs\fonts/n019003l.pfb... 2291320 946479 1594968 288125 3 done. Error: /typecheck in --lt-- Operand stack: --dict:4/4(L)-- F2 1 --dict:5/5(L)-- --dict:5/5(L)-- --dict:15/16(ro)(G)-- --nostringval-- --nostringval-- 1 --nostringval-- 1 --nostringval-- Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- false 1 %stopped_push 1 3 %oparray_pop 1 3 %oparray_pop 1 3 %oparray_pop 1 3 %oparray_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- false 1 %stopped_push --nostringval-- %loop_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- Dictionary stack: --dict:1129/1686(ro)(G)-- --dict:0/20(G)-- --dict:79/200(L)-- --dict:105/127(ro)(G)-- --dict:251/347(ro)(G)-- --dict:21/24(L)-- --dict:4/6(L)-- --dict:20/20(L)-- --dict:10/13(L)-- Current allocation mode is local pdf_page failed __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Example in pdf() help file (PR#8083)
This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --27464147-1188682158-1124696849=:32369 Content-Type: TEXT/PLAIN; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Please consult the help _file_! This is correct in the file, but has been= =20 incorrectly marked for conversion (now fixed). On Mon, 22 Aug 2005 [EMAIL PROTECTED] wrote: > > The example in the help file for pdf() plots the characters outside > the plotting area in this for loop: > >for(i in c(32:255)) { > x <- i > y <- i > points(x, y, pch=3Di) > } > > The following loop seems to be working as intended > > for(i in c(32:255)) { > x <- (i-31)%%16 > y <- (i-31)%/%16 > points(x, y, pch=3Di) > } No, i%%16 etc was intended. > As an extra observation, with code page ISOLatin2, the pdf-file fails to > open in Ghostview 4.7 using ghostscript 8.51. Error message below. In > Acrobat Reader 7.0 it opens without problems. It is quite possible that > it is the settings on my computer that causes the error, It's nothing to do with R, but to do with how your computer is set. BTW, I am pretty sure this is GSView 4.7, a different program. > but I include the dump of the error message, just in case anybody was > interested > > Best regards > > Erik J=F8rgensen > Danish Institute of Agricultural Sciences > > --please do not edit the information below-- > > Version: > platform =3D i386-pc-mingw32 > arch =3D i386 > os =3D mingw32 > system =3D i386, mingw32 > status =3D > major =3D 2 > minor =3D 1.1 > year =3D 2005 > month =3D 06 > day =3D 20 > language =3D R > > Windows XP Professional (build 2600) Service Pack 2.0 > > Locale: > LC_COLLATE=3DDanish_Denmark.1252;LC_CTYPE=3DDanish_Denmark.1252;LC_MONETA= RY=3DDanish_Denmark.1252;LC_NUMERIC=3DC;LC_TIME=3DDanish_Denmark.1252 > > Search Path: > .GlobalEnv, package:lattice, package:methods, package:stats, > package:graphics, package:grDevices, package:utils, package:datasets, > Autoloads, package:base > > > > --- > > GSview 4.7 2005-03-26 > AFPL Ghostscript 8.51 (2005-04-18) > Copyright (C) 2005 artofcode LLC, Benicia, CA. All rights reserved. > This software comes with NO WARRANTY: see the file PUBLIC for details. > Scanning PDF file > %GSVIEW_PDF_PAGES: 1 1 > Displaying PDF page 1 > %GSVIEW_PDF_PAGE: 1 > %GSVIEW_PDF_MEDIA: [0 0 432 432] > %GSVIEW_PDF_ROTATE: 0 > Loading NimbusSanL-Regu font from c:\gs\fonts/n019003l.pfb... 2291320 > 946479 1594968 288125 3 done. > Error: /typecheck in --lt-- > Operand stack: >--dict:4/4(L)-- F2 1 --dict:5/5(L)-- --dict:5/5(L)-- > --dict:15/16(ro)(G)-- --nostringval-- --nostringval-- 1 > --nostringval-- 1 --nostringval-- > Execution stack: >%interp_exit .runexec2 --nostringval-- --nostringval-- > --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- > false 1 %stopped_push 1 3 %oparray_pop 1 3 > %oparray_pop 1 3 %oparray_pop 1 3 %oparray_pop .runexec2 > --nostringval-- --nostringval-- --nostringval-- 2 > %stopped_push --nostringval-- --nostringval-- --nostringval-- > --nostringval-- --nostringval-- %array_continue --nostringval-- > false 1 %stopped_push --nostringval-- %loop_continue > --nostringval-- --nostringval-- --nostringval-- --nostringval-- > --nostringval-- --nostringval-- %array_continue --nostringval-- > Dictionary stack: >--dict:1129/1686(ro)(G)-- --dict:0/20(G)-- --dict:79/200(L)-- > --dict:105/127(ro)(G)-- --dict:251/347(ro)(G)-- --dict:21/24(L)-- > --dict:4/6(L)-- --dict:20/20(L)-- --dict:10/13(L)-- > Current allocation mode is local > pdf_page failed > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > > --=20 Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 --27464147-1188682158-1124696849=:32369-- __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Implementing a single-precision class with raw
On Fri, 19 Aug 2005, Colin A. Smith wrote: > A package that I develop (xcms) sometimes needs to read and process > vectors several hundreds of megabytes in size. (They only represent > parts of a large data sets which can approach nearly 100GB.) > Unfortunately, R sometimes hits the 2GB memory limit of Win32. The rw-FAQ explains why that is _not_ the limit! > To help cut the memory footprint in half, I'm implementing a "float" > class as a subclass of "raw". Why via "raw"? I believe the intention is that this sort of thing be done via external references, but as float and int are the same size on all current platforms, I would have considered R integers for storage. Then for example subsetting would work and you had a 4x larger size limit on 64-bit platforms. (You would also have got automatic handling of endianness.) > Because almost all the computation on the large vectors is done in C > code, having a somewhat limited single-precision data type is okay. > > I've run into a limitation with the .C() function where it does not > handle raw vectors, which it will do in 2.2.0. That is just not true! > In the meantime, I'm using the .Call() function to access the raw > vectors. However, there don't seem to be any macros for handling raw > vectors in Rdefines.h. So? We recommend using Rinternals.h: Rdefines.h is a compatibility wrapper for macros from S4. The raw type has not attempted to be compatible with S4, and we are not aware of any user who has compiled S4 code using raw vectors that (s)he wishes to port to R. (The R-exts.texi manual has been rather too optimistic about Rdefines.h: as you need to use SET_STRING_ELT and SET_VECTOR_ELT in R, you are rather limited as to what you can do in S4 style. This has been so since R 1.2.0 and Rdefines.h has hardly been updated since.) > I've made a guess at what those macros would be and was wondering > whether my guesses were correct and/or might be included in 2.2.0: > > #define NEW_RAW(n) allocVector(RAWSXP,n) > #define RAW_POINTER(x) (RAW(x)) > #define AS_RAW(x) coerceVector(x,RAWSXP) > > I'm not sure whether coerceVector(x,RAWSXP) will actually work. You should have read the code to find out (people answering your comment would have had to). It will `actually work', but it may not do whatever it is that you expect. (It interprets its input as integer (decimal if a string) representations of the bytes.) This is in contrast to S, where I have no idea precisely what AS_RAW is supposed to do and no code to read. (as(, "raw") seems to do wierd and unpredictable things, though, and the Green Book suggests that coercion probably is not intended to work.) For completeness I have added my (informed) guesses to Rdefines.h in R-devel. > Also, there isn't an Rf_isRaw() function, which would be useful for an > IS_RAW(x) macro. Why would this be necessary? TYPEOF(x) == RAWSXP is all that is needed. > Another issue with the "float" class is that it will run into endian > issues if it ever gets saved to disk and moved cross-platform. I don't > really anticipate that happening but it might be nice to incorporate > serialization hooks if possible. Are there any facilities in R for > doing that? See the comment above. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] [Virus Check]
GROUP Watchdog Server: HONDASMTP2 --- Sua mensagem nao foi entregue pois continha virus. Your mail item contained attachments that have been virus infected. --- Mail-Info From: r-devel@r-project.org To:[EMAIL PROTECTED] Rec.: [EMAIL PROTECTED] Date: 22/08/2005 07:40:45 Subject: massas! --- file contains virus:botao.zip __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Internationalization questions
Dear Brian, > -Original Message- > From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] > Sent: 22 août 2005 01:47 > To: John Fox > Cc: r-devel@stat.math.ethz.ch > Subject: Re: [Rd] Internationalization questions > > On Sun, 21 Aug 2005, John Fox wrote: > > > Dear R-devel list members: > > > > I have two internationalization questions, related to > questions that I > > posed previously. These pertain to Windows (I've tried under Win XP > > but assume the issue is more general) and R 2.1.1 patched > and 2.2.0 devel. > > > > (1) I've noticed that the standard Windows dialogs in R -- whether > > initiated from the Rgui menus, from winDialog(), or from tcltk > > functions such as > > tkmessageBox() -- do not have button labels translated when > running in > > a non-English locale. For example, when running in a French locale, > > the command > > > > winDialog(type="yesnocancel", message=gettext("Save workspace > > image?", > > domain="RGui")) > > > > produces a dialog box with the message translated to > "Sauver une image > > de la session?", but the buttons still read "Yes", "No", > and "Cancel". > > > > Is this the intended behaviour? Is there any way to get the button > > text translated? I've implemented a partial solution that uses a > > substitute for tkmessageBox(), but it is a bit awkward. > > You need to have Windows set to be in French dialogs, not > just the locale set to French. This is on the second page of > the Regional settings doalogs in WinXP. It is intended, as > it makes all Windows dialogs work consistently. (You can > have different settings on the three pages, but not all > combinations work successfully -- the current rw-FAQ has some > comments.) > On my XP system, the tabs are (in order) Regional Options, Languages, and Advanced. I have now set all three to "French (Canada)" -- including in the subdialog produced by the Details button under Languages, and rebooted. I still get English button labels. I've just read over the rw-FAQ from R 2.2.0 devel, but will read it more carefully. I guess that I'm willing to accept that Windows users who use languages other than English know how to set up their systems properly. > > (2) I'm still looking for a reliable way to determine whether R is > > using English. Currently, I have the function > > > > English <- function() { > >env <- Sys.getenv() > >names(env) <- toupper(names(env)) > >LANG <- env["LANGUAGE"] > >LC_CTYPE <- Sys.getlocale("LC_CTYPE") > >if (!is.na(LANG)) length(grep("^en", LANG, ignore.case=TRUE)) > 0 > >else LC_CTYPE == "C" || length(grep("^en", LC_CTYPE, > > ignore.case=TRUE)) > >> 0 > >} > > > > > > (adapting and extending a suggestion by Simon Urbanek) which checks > > not just the locale but also for an environment variable named > > LANGUAGE. Is this sufficient? > > Using English for what? (See my comments above.) For > messages, yes, it > covers all the quirks we know about in the major OSes. > Checking for English messages is sufficient for my purposes. Thanks for your help, John > Brian __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] doc - matrix multiplication (PR#8069)
Full_Name: John Perry Version: 2.1.1 OS: Windows Submission from: (NULL) (155.140.122.227) help("*") Could you add the following? See Also: '%*%' for matrix multiplication __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] is.numeric (PR#8067)
Full_Name: Joern Toedling Version: 2.1.0 OS: Linux Submission from: (NULL) (193.62.198.2) Maybe, it's supposed to be a feature rather than a bug, but I find it quite strange that > is.numeric(NaN) returns TRUE, when NaN means 'Not a Number' __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] is.numeric (PR#8067)
Please do read the help page before firing off a bug report, as we do ask in several places. It says 'is.numeric' returns 'TRUE' if its argument is of type numeric or type integer and 'FALSE' otherwise. and > typeof(NaN) [1] "double" (numeric and double are synonyms for types). Working as documented is a not a bug. On Mon, 15 Aug 2005 [EMAIL PROTECTED] wrote: > Full_Name: Joern Toedling > Version: 2.1.0 We do ask for reports to be made on the current version of R. > OS: Linux > Submission from: (NULL) (193.62.198.2) > > > Maybe, it's supposed to be a feature rather than a bug, but I find it quite > strange that >> is.numeric(NaN) > returns TRUE, when NaN means 'Not a Number' -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Internationalization questions
Dear Brian, > -Original Message- > From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] > Sent: Monday, August 22, 2005 8:02 AM > To: John Fox > Cc: r-devel@stat.math.ethz.ch > Subject: RE: [Rd] Internationalization questions > > On Mon, 22 Aug 2005, John Fox wrote: > > > Dear Brian, > > > >> -Original Message- > >> From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] > >> Sent: 22 août 2005 01:47 > >> To: John Fox > >> Cc: r-devel@stat.math.ethz.ch > >> Subject: Re: [Rd] Internationalization questions > >> > >> On Sun, 21 Aug 2005, John Fox wrote: > >> > >>> Dear R-devel list members: > >>> > >>> I have two internationalization questions, related to > >> questions that I > >>> posed previously. These pertain to Windows (I've tried > under Win XP > >>> but assume the issue is more general) and R 2.1.1 patched > >> and 2.2.0 devel. > >>> > >>> (1) I've noticed that the standard Windows dialogs in R > -- whether > >>> initiated from the Rgui menus, from winDialog(), or from tcltk > >>> functions such as > >>> tkmessageBox() -- do not have button labels translated when > >> running in > >>> a non-English locale. For example, when running in a > French locale, > >>> the command > >>> > >>> winDialog(type="yesnocancel", message=gettext("Save workspace > >>> image?", > >>> domain="RGui")) > >>> > >>> produces a dialog box with the message translated to > >> "Sauver une image > >>> de la session?", but the buttons still read "Yes", "No", > >> and "Cancel". > >>> > >>> Is this the intended behaviour? Is there any way to get > the button > >>> text translated? I've implemented a partial solution that uses a > >>> substitute for tkmessageBox(), but it is a bit awkward. > >> > >> You need to have Windows set to be in French dialogs, not just the > >> locale set to French. This is on the second page of the Regional > >> settings doalogs in WinXP. It is intended, as it makes > all Windows > >> dialogs work consistently. (You can have different > settings on the > >> three pages, but not all combinations work successfully -- the > >> current rw-FAQ has some > >> comments.) > >> > > > > On my XP system, the tabs are (in order) Regional Options, > Languages, > > and Advanced. I have now set all three to "French (Canada)" -- > > including in the subdialog produced by the Details button under > > Languages, and rebooted. I still get English button labels. > > At the bottom of the Languages tab there is a setting for > `menus and dialogs'. I got a short list of languages, e.g. > 'francais' for that item. > You have to log out and log in again to make a change stick > (and it tells you that.) That does work for me (and I tested > it again before answering you, and have also tested Italian > in the past). I wonder if you have had to have used that > language in a past reboot to make this work > There is no such setting on the Languages tab on my system (XP Pro Version 2002 SP2), even though I've now rebooted using French. The tab has only "Text services and input languages" with a Details button, and "Supplemental language support" with two check boxes for "Install files for complex script etc." and "Install files for East Asian languages." I'm reluctant to waste more of your time -- this is clearly a Windows issue and not an R issue. Thanks again for your help, John __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Internationalization questions
On Mon, 22 Aug 2005, John Fox wrote: Dear Brian, -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: 22 août 2005 01:47 To: John Fox Cc: r-devel@stat.math.ethz.ch Subject: Re: [Rd] Internationalization questions On Sun, 21 Aug 2005, John Fox wrote: Dear R-devel list members: I have two internationalization questions, related to questions that I posed previously. These pertain to Windows (I've tried under Win XP but assume the issue is more general) and R 2.1.1 patched and 2.2.0 devel. (1) I've noticed that the standard Windows dialogs in R -- whether initiated from the Rgui menus, from winDialog(), or from tcltk functions such as tkmessageBox() -- do not have button labels translated when running in a non-English locale. For example, when running in a French locale, the command winDialog(type="yesnocancel", message=gettext("Save workspace image?", domain="RGui")) produces a dialog box with the message translated to "Sauver une image de la session?", but the buttons still read "Yes", "No", and "Cancel". Is this the intended behaviour? Is there any way to get the button text translated? I've implemented a partial solution that uses a substitute for tkmessageBox(), but it is a bit awkward. You need to have Windows set to be in French dialogs, not just the locale set to French. This is on the second page of the Regional settings doalogs in WinXP. It is intended, as it makes all Windows dialogs work consistently. (You can have different settings on the three pages, but not all combinations work successfully -- the current rw-FAQ has some comments.) On my XP system, the tabs are (in order) Regional Options, Languages, and Advanced. I have now set all three to "French (Canada)" -- including in the subdialog produced by the Details button under Languages, and rebooted. I still get English button labels. At the bottom of the Languages tab there is a setting for `menus and dialogs'. I got a short list of languages, e.g. 'francais' for that item. You have to log out and log in again to make a change stick (and it tells you that.) That does work for me (and I tested it again before answering you, and have also tested Italian in the past). I wonder if you have had to have used that language in a past reboot to make this work Brian -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Copy and paste with X11 (PR#8085)
Full_Name: Kwang-Youn Kim Version: 2.1.1 OS: OS X 10.4 Submission from: (NULL) (128.255.125.51) When running R 2.1.1 under Mac OS X 10.4.2 X11, copying and pasting a large segment of code from vi, typically more than 10 lines at a time will paste some garbage information rendering incorrect code to be pasted. The current hardware that I am running is a Power Mac Dual 2.3Ghz with 4.5 GB of memory. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Fetching Warning Messages
Hi, I am facing one problem of fetching R warning messages in Java Code using Rserve. It is easier to trap R Error messages by using catching RSrvException. I came to know one way of fetching R Warning messages, i.e. using "withCallingHandlers", below is my Java Program, which uses withCallingHandlers of R : import org.rosuda.JRclient.*; ---RWarning.java--- class RWarning { public static void main(String args[]) { try { String hostName = null; hostName = args[0]; Rconnection c = new Rconnection(hostName); c.voidEval("lastWarning <- NULL"); c.voidEval("withCallingHandlers( {x<-sqrt(-9);y<-matrix(1:9,ncol=4);z<-sqrt(4)} , warning = function (w) { lastWarning <<- paste(lastWarning,as.character(w))})"); //This will generate warning message[sqrt(-9)], another warning message [ matrix(1:9,ncol=4) ] and successful completion [ sqrt(4) ] System.out.println(c.eval("z").asDouble()); System.out.println(c.eval("lastWarning").asString()); c.close(); System.out.println("DONE"); } catch(RSrvException e) { System.out.println("Error : " + e.getMessage()); e.printStackTrace(); } } } ---End Of RWarning.java--- Output of above program is (as expected) : 2.0 simpleWarning in sqrt(-9): NaNs produced simpleWarning: data length [9] is not a sub-multiple or multiple of the number of columns [4] in matrix DONE Now my query is that if there is any way of using warnings() function in Java Program to fetch all warnings. I used it in my program but returns me NULL instead of warning messages. I also used last.warning but it Java Program gives an error saying that last.warning object is not found. I have pasted both the java code below : This is the java program that I have written to use "last.warning" object of R. Please explain me where the error could be. Code of RWarning1.java import org.rosuda.JRclient.*; class RWarning1 { public static void main(String args[]) { try { String hostName = null; hostName = args[0]; Rconnection c = new Rconnection(hostName); System.out.println(c.eval("x<-sqrt(-9)").asString()); System.out.println(c.eval("last.warning").asString()); c.close(); System.out.println("DONE"); } catch(RSrvException e) { System.out.println("Error : " + e.getMessage()); e.printStackTrace(); } } } End of code of RWarning1.java-- output of RWarning1.class null Error : Request return code: 127 [request status: Error (127)] org.rosuda.JRclient.RSrvException: Request return code: 127 [request status: Err or (127)] at org.rosuda.JRclient.Rconnection.eval(Rconnection.java:190) at RWarning.main(RWarning.java:13) In other words, when I use "last.warning" in eval method, I simply get an exception, instead of value of last.warning. Below is the java code of using warnings() function. Code of RWarning2.java import org.rosuda.JRclient.*; class RWarning2 { public static void main(String args[]) { try { String hostName = null; hostName = args[0]; Rconnection c = new Rconnection(hostName); System.out.println(c.eval("x<-sqrt(-9)").asString()); System.out.println(c.eval("paste(capture.output(warnings()),collapse='\n')") .asString()); c.close(); System.out.println("DONE"); } catch(RSrvException e) { System.out.println("Error : " + e.getMessage()); e.printStackTrace(); } } } End of code of RWarning2.java-- output of RWarning2.class null NULL DONE Please let me know where I am making mistake. Regards, Nikhil Shah __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Fetching Warning Messages
Please read the help page on options("warn") and see what warnings() does. (I am pretty sure you have asked this and been told before.) There should not be an object called last.warning in your example. On Mon, 22 Aug 2005, Nikhil Shah wrote: > Hi, > >I am facing one problem of fetching R warning messages in Java Code > using Rserve. It is easier to trap R Error messages by using catching > RSrvException. I came to know one way of fetching R Warning messages, i.e. > using "withCallingHandlers", below is my Java Program, which uses > withCallingHandlers of R : > import org.rosuda.JRclient.*; > > ---RWarning.java--- > class RWarning > { > public static void main(String args[]) > { > try > { > String hostName = null; > hostName = args[0]; > Rconnection c = new Rconnection(hostName); > c.voidEval("lastWarning <- NULL"); > c.voidEval("withCallingHandlers( > {x<-sqrt(-9);y<-matrix(1:9,ncol=4);z<-sqrt(4)} , warning = function (w) { > lastWarning <<- paste(lastWarning,as.character(w))})"); //This will generate > warning message[sqrt(-9)], another warning message [ matrix(1:9,ncol=4) ] > and successful completion [ sqrt(4) ] >System.out.println(c.eval("z").asDouble()); >System.out.println(c.eval("lastWarning").asString()); >c.close(); >System.out.println("DONE"); > } > catch(RSrvException e) > { > System.out.println("Error : " + e.getMessage()); > e.printStackTrace(); > } > } > } > ---End Of RWarning.java--- > > Output of above program is (as expected) : > > 2.0 > simpleWarning in sqrt(-9): NaNs produced > simpleWarning: data length [9] is not a sub-multiple or multiple of the > number of columns [4] in matrix > > DONE > > > > Now my query is that if there is any way of using warnings() function > in Java Program to fetch all warnings. I used it in my program but returns > me NULL instead of warning messages. I also used last.warning but it Java > Program gives an error saying that last.warning object is not found. I have > pasted both the java code below : > > This is the java program that I have written to use "last.warning" object of > R. Please explain me where the error could be. > > Code of RWarning1.java > > import org.rosuda.JRclient.*; > > class RWarning1 > { > public static void main(String args[]) > { >try >{ > String hostName = null; > hostName = args[0]; > Rconnection c = new Rconnection(hostName); > System.out.println(c.eval("x<-sqrt(-9)").asString()); > System.out.println(c.eval("last.warning").asString()); > c.close(); > System.out.println("DONE"); >} >catch(RSrvException e) >{ > System.out.println("Error : " + e.getMessage()); > e.printStackTrace(); >} > } > } > End of code of RWarning1.java-- > > output of RWarning1.class > > null > Error : Request return code: 127 [request status: Error (127)] > org.rosuda.JRclient.RSrvException: Request return code: 127 [request status: > Err > or (127)] >at org.rosuda.JRclient.Rconnection.eval(Rconnection.java:190) >at RWarning.main(RWarning.java:13) > > In other words, when I use "last.warning" in eval method, I simply get an > exception, instead of value of last.warning. > > > Below is the java code of using warnings() function. > > Code of RWarning2.java > > import org.rosuda.JRclient.*; > > class RWarning2 > { > public static void main(String args[]) > { > try > { >String hostName = null; >hostName = args[0]; >Rconnection c = new Rconnection(hostName); >System.out.println(c.eval("x<-sqrt(-9)").asString()); > > System.out.println(c.eval("paste(capture.output(warnings()),collapse='\n')") > .asString()); >c.close(); >System.out.println("DONE"); > } > catch(RSrvException e) > { >System.out.println("Error : " + e.getMessage()); >e.printStackTrace(); > } > } > } > End of code of RWarning2.java-- > output of RWarning2.class > > null > NULL > DONE > > > Please let me know where I am making mistake. > > Regards, > > Nikhil Shah > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > > -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Package tests: best practices
I'm writing some tests for a package and I have a few questions regarding best practices. I've read "tests subdirectory" paragraph in writing R extension, but I'm left wanting more. Firstly, can I assume that the document root will always be set to the test directory? (that what a couple of quick tests seemed to show) Obviously, I want to test the code in my package - how do I load it? I assume I can't use library(XXX) because that will load the currently installed version - should I source in all ../R/*.r instead? Thanks for your advice, Hadley __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Package tests: best practices
On Mon, 22 Aug 2005, hadley wickham wrote: > I'm writing some tests for a package and I have a few questions > regarding best practices. I've read "tests subdirectory" paragraph in > writing R extension, but I'm left wanting more. > Firstly, can I assume that the document root will always be set to the > test directory? (that what a couple of quick tests seemed to show) The working directory will be the tests directory as used, and all the tests subdirectory in the sources is copied there. R does not have `document root', AFAIK. > Obviously, I want to test the code in my package - how do I load it? > I assume I can't use library(XXX) because that will load the currently > installed version - should I source in all ../R/*.r instead? You assume wrong: you should use the version installed for checking by library(xxx): R_LIBS is explicitly set to point to it first. I've added some further comments to R-exts, but it seems that quite a few people have worked this out from the existing info and there are several examples in the R sources and recommended packages. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] An lgrind definition for the S language
I seem to recall discussion of an language definition file for S for use with the lgrind utility but I can't find any trace of it in an R Site Search. The lgrind utility takes a file of code in a particular programming language and prepares it for "pretty printing" in LaTeX. In my version the available language definitions are $ lgrind -s When specifying a language case is insignificant. You can use the name of the language, or, where available, one of the synonyms in parantheses. Thus the following are legal and mark Tcl/Tk, Pascal and Fortran input, respectively: lgrind -ltcl/tk ... lgrind -lpaSCAL ... lgrind -lf ... The list of languages currently available in your lgrindef file: Ada MLisp (Emacs Mock Lisp) Asm SML/NJ (ML) Asm68 Scheme (scm) BASIC model Batch (bat) Modula2 (mod2, m2) C Pascal (pas, p, bp) C++ (CC) PERL (pl) csh PostScript (ps) FORTRAN (f77, f) PROLOG Gnuplot Python (py) Icon RATFOR IDL RLaB ISP Russell Java SAS Kimwitu++ (kimw) SDL LaTeX sh LDL SICStus Lex src Linda SQL make Tcl/Tk (tcl, tk) MASM VisualBasic (vbasic) MATLABVMSasm Mercury yacc (y) Does anyone know of a similar facility for S code? __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] An lgrind definition for the S language
On Mon, 2005-08-22 at 12:57 -0500, Douglas Bates wrote: > I seem to recall discussion of an language definition file for S for > use with the lgrind utility but I can't find any trace of it in an R > Site Search. The lgrind utility takes a file of code in a particular > programming language and prepares it for "pretty printing" in LaTeX. > In my version the available language definitions are > > $ lgrind -s > When specifying a language case is insignificant. You can use the > name of the language, or, where available, one of the synonyms in > parantheses. Thus the following are legal and mark Tcl/Tk, Pascal > and Fortran input, respectively: >lgrind -ltcl/tk ... >lgrind -lpaSCAL ... >lgrind -lf ... > The list of languages currently available in your lgrindef file: > Ada MLisp (Emacs Mock Lisp) > Asm SML/NJ (ML) > Asm68 Scheme (scm) > BASIC model > Batch (bat) Modula2 (mod2, m2) > C Pascal (pas, p, bp) > C++ (CC) PERL (pl) > csh PostScript (ps) > FORTRAN (f77, f) PROLOG > Gnuplot Python (py) > Icon RATFOR > IDL RLaB > ISP Russell > Java SAS > Kimwitu++ (kimw) SDL > LaTeX sh > LDL SICStus > Lex src > Linda SQL > make Tcl/Tk (tcl, tk) > MASM VisualBasic (vbasic) > MATLABVMSasm > Mercury yacc (y) > > Does anyone know of a similar facility for S code? Doug, A search using Jon Baron's page came up with the following thread: https://stat.ethz.ch/pipermail/r-help/2000-April/004898.html by Kjetil Kjernsmo and the following post by Torsten Hothorn: https://stat.ethz.ch/pipermail/r-help/2000-March/004345.html I checked "Rhelp 1997-2001" on Jon's search page, otherwise these would be missed. Another approach would be to use Google with the following: lgrind site:https://stat.ethz.ch which would search the archives, including r-devel. HTH, Marc __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] boxplot.formula and questions about calls and formulas
I am trying to adapt boxplot.formula (in graphics) to accept an additional parameter, weights. I already managed to adapt boxplot.default to do this. boxplot.formula prepares the data for a call to boxplot.default and to achieve that does the following: It takes a formula like x~g*h as the first argument, and then by using m <- match.call(expand.dots = FALSE) saves the call. It transforms the call m$na.action <- na.action # force use of default for this method m[[1]] <- as.name("model.frame") and then evaluates the modified call mf <- eval(m, parent.frame()) print(m) gives model.frame(formula = x ~ g * h) Then it uses components of mf for the call to boxplot.default. m has a component m$formula containing the parsed model formula. mode(m$formula) is "call". In our case, deparse(m$formula) gives a string representation of the formula: "x~g*h". I want to replace the response variable (in our case x) by the weights variable, which in the string expression can be done easily with strsplit and paste. Then I need to reconvert the modified string to a call. So I create newmodelstring<-"weights~g*h" and try m$formula<-as.call(parse(newmodelstring)) print(m) gives model.frame(formula = weights ~ g * h()) When I try to evaluate the modified m this does not work. When I try to evaluate m with this modification I get Error in model.frame(formula = weights ~ g * h()) : attempt to apply non-function Is there a way to get rid of the empty parentheses at the end of the formula? I think then my code could work. -- Erich Neuwirth, Didactic Center for Computer Science University of Vienna Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-39902 Fax: +43-1-4277-9399 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Questions about calls and formulas
I am trying to adapt boxplot.formula (in graphics) to accept an additional parameter, weights. I already managed to adapt boxplot.default to do this. boxplot.formula prepares the data for a call to boxplot.default and to achieve that does the following: It takes a formula like x~g*h as the first argument, and then by using m <- match.call(expand.dots = FALSE) saves the call. It transforms the call m$na.action <- na.action # force use of default for this method m[[1]] <- as.name("model.frame") and then evaluates the modified call mf <- eval(m, parent.frame()) print(m) gives model.frame(formula = x ~ g * h) Then it uses components of mf for the call to boxplot.default. m has a component m$formula containing the parsed model formula. mode(m$formula) is "call". In our case, deparse(m$formula) gives a string representation of the formula: "x~g*h". I want to replace the response variable (in our case x) by the weights variable, which in the string expression can be done easily with strsplit and paste. Then I need to reconvert the modified string to a call. So I create newmodelstring<-"weights~g*h" and try m$formula<-as.call(parse(newmodelstring)) print(m) gives model.frame(formula = weights ~ g * h()) When I try to evaluate the modified m this does not work. When I try to evaluate m with this modification I get Error in model.frame(formula = weights ~ g * h()) : attempt to apply non-function Is there a way to get rid of the empty parentheses at the end of the formula? I think then my code could work. -- Erich Neuwirth, Didactic Center for Computer Science University of Vienna Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-39902 Fax: +43-1-4277-9399 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Questions about calls and formulas
On 8/22/05, Erich Neuwirth <[EMAIL PROTECTED]> wrote: > I am trying to adapt boxplot.formula (in graphics) to accept an > additional parameter, weights. > I already managed to adapt boxplot.default to do this. > > boxplot.formula prepares the data for a call to boxplot.default and to > achieve that does the following: It takes a formula like > > x~g*h > > as the first argument, and then by using > > m <- match.call(expand.dots = FALSE) > > saves the call. It transforms the call > > m$na.action <- na.action # force use of default for this method > m[[1]] <- as.name("model.frame") > > and then evaluates the modified call > mf <- eval(m, parent.frame()) > > print(m) > gives > model.frame(formula = x ~ g * h) > > Then it uses components of mf for the call to boxplot.default. > > m has a component m$formula containing the parsed model formula. > mode(m$formula) is "call". > In our case, deparse(m$formula) gives a string representation of the > formula: "x~g*h". > I want to replace the response variable (in our case x) by the weights > variable, which in the string expression can be done easily with > strsplit and paste. Then I need to reconvert the modified string to a call. > > So I create newmodelstring<-"weights~g*h" and try > > m$formula<-as.call(parse(newmodelstring)) > > print(m) > gives > model.frame(formula = weights ~ g * h()) > > > When I try to evaluate the modified m this does not work. When I try to > evaluate m with this modification I get > > Error in model.frame(formula = weights ~ g * h()) : > attempt to apply non-function > > Is there a way to get rid of the empty parentheses at the > end of the formula? I think then my code could work. > > -- > Erich Neuwirth, Didactic Center for Computer Science > University of Vienna > Visit our SunSITE at http://sunsite.univie.ac.at > Phone: +43-1-4277-39902 Fax: +43-1-4277-9399 > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > I think the preferred way to do this is using substitute although formulas are a bit tricky in that you need to eval them after the substitution to make sure that the object has class "formula". > (foo <- eval(substitute(x ~ g * h, list(x = as.name("weights") weights ~ g * h > class(foo) [1] "formula" __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Questions about calls and formulas
> >>(foo <- eval(substitute(x ~ g * h, list(x = as.name("weights") > > weights ~ g * h > >>class(foo) > > [1] "formula" > > ff<-formula("x~g*h") (foo<-eval(substitute(ff,list(x=as.name("weights") gives x ~ g * h what needs to be done to ff for the substitution to work? I found a way of doing it using string substitution and applying formula (instead of as.call) to the string, but I would like to be able to do it using substitution. This is what I currently do: myexpr<-paste("weights ~",strsplit(deparse(m$formula),"~")[[1]][2]) m$formula<-formula(myexpr) -- Erich Neuwirth, Didactic Center for Computer Science University of Vienna Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-39902 Fax: +43-1-4277-9399 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Questions about calls and formulas
On 8/22/05, Erich Neuwirth <[EMAIL PROTECTED]> wrote: > > > >>(foo <- eval(substitute(x ~ g * h, list(x = as.name("weights") > > > > weights ~ g * h > > > >>class(foo) > > > > [1] "formula" > > > > > > ff<-formula("x~g*h") > (foo<-eval(substitute(ff,list(x=as.name("weights") > > gives > > x ~ g * h > > what needs to be done to ff for the substitution to work? > > I found a way of doing it using string substitution > and applying formula (instead of as.call) to the string, > but I would like to be able to do it using substitution. > > This is what I currently do: > > myexpr<-paste("weights ~",strsplit(deparse(m$formula),"~")[[1]][2]) > m$formula<-formula(myexpr) Try do.call like this: ff <- x ~ g*h do.call("substitute", list(ff, list(x = as.name("weight" __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Questions about calls and formulas
> Try do.call like this: > > ff <- x ~ g*h > do.call("substitute", list(ff, list(x = as.name("weight" > It is even more complicated. All I know is that ff is a formula with an expression on the left hand side. This expression needs to be replaced by "weights". According to the documentation, substitute only handles replacement of variables by something else, and that is not enough in my case. -- Erich Neuwirth, Didactic Center for Computer Science University of Vienna Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-39902 Fax: +43-1-4277-9399 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] bizarre signif stars in Sweave latex
On Mon, Aug 22, 2005 at 07:42:21AM +0100, Prof Brian Ripley wrote: > What locale is this? > > My guess is that this is a UTF-8 locale. Yes. > Sys.getlocale() [1] "LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C" > If so, you need to tell latex > the input is in UTF-8, which you can do in the current LaTeX release > (you need 2003/12/01). As I recall you do this by > > \usepackage[utf8]{inputenc} Right. This works. Silly me. I fell like the drunk looking for his keys under the lamppost. Here I was looking for a solution in the R docs, when I should have been looking in the LaTeX Companion. -- Charles Geyer Professor, School of Statistics University of Minnesota [EMAIL PROTECTED] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] RFC: "loop connections"
I've just implemented a generalization of R's text connections, to also support reading/writing raw binary data. There is very little new code to speak of. For input connections, I wrote code to populate the old text connection buffer from a raw vector, and provided a new raw_read() method. For output connections, I wrote a raw_write() to append to a raw vector. On input, the mode (text or binary) is determined by the data type of the input object; on output, I use the requested output mode (i.e. "w" / "wb"). For example: > con <- loopConnection("r", "wb") > a <- c(10,100,1000) > writeBin(a, con, size=4) > r [1] 00 00 20 41 00 00 c8 42 00 00 7a 44 > close(con) > con <- loopConnection(r) > readBin(con, "double", n=3, size=4) [1] 10 100 1000 > close(con) I think "loop connection" is a better name for this sort of connection than "text connection" was even for the old version; that confuses the mode of the connection (text vs binary) with the mechanism (file, socket, etc). I've appended a patch to the end of this message. As implemented here, textConnection is replaced by loopConnection but functionally this is a superset of the old textConnection. For compatibility, one could add: textConnection <- function(...) loopConnection(...) The patch is against R-2.1.1. I can investigate whether any changes are required for the current development tree. I can also update the documentation files as required. I thought I'd first check whether anyone else thought this was worth inclusion before spending more time on it. The raw_write() code could be improved with smarter memory allocation (grabbing bigger chunks rather than reallocating the raw vector for every write), but this is at least a proof of principle. -- David Hinds --- src/main/connections.c.orig 2005-06-17 19:05:02.0 -0700 +++ src/main/connections.c 2005-08-22 15:54:03.156038200 -0700 @@ -1644,13 +1644,13 @@ return ans; } -/* --- text connections - */ +/* --- loop connections - */ /* read a R character vector into a buffer */ static void text_init(Rconnection con, SEXP text) { int i, nlines = length(text), nchars = 0; -Rtextconn this = (Rtextconn)con->private; +Rloopconn this = (Rloopconn)con->private; for(i = 0; i < nlines; i++) nchars += strlen(CHAR(STRING_ELT(text, i))) + 1; @@ -1668,19 +1668,35 @@ this->cur = this->save = 0; } -static Rboolean text_open(Rconnection con) +/* read a R raw vector into a buffer */ +static void raw_init(Rconnection con, SEXP raw) +{ +int nbytes = length(raw); +Rloopconn this = (Rloopconn)con->private; + +this->data = (char *) malloc(nbytes); +if(!this->data) { + free(this); free(con->description); free(con->class); free(con); + error(_("cannot allocate memory for raw connection")); +} +memcpy(this->data, RAW(raw), nbytes); +this->nchars = nbytes; +this->cur = this->save = 0; +} + +static Rboolean loop_open(Rconnection con) { con->save = -1000; return TRUE; } -static void text_close(Rconnection con) +static void loop_close(Rconnection con) { } -static void text_destroy(Rconnection con) +static void loop_destroy(Rconnection con) { -Rtextconn this = (Rtextconn)con->private; +Rloopconn this = (Rloopconn)con->private; free(this->data); /* this->cur = this->nchars = 0; */ @@ -1689,7 +1705,7 @@ static int text_fgetc(Rconnection con) { -Rtextconn this = (Rtextconn)con->private; +Rloopconn this = (Rloopconn)con->private; if(this->save) { int c; c = this->save; @@ -1700,48 +1716,69 @@ else return (int) (this->data[this->cur++]); } -static double text_seek(Rconnection con, double where, int origin, int rw) +static double loop_seek(Rconnection con, double where, int origin, int rw) { -if(where >= 0) error(_("seek is not relevant for text connection")); +if(where >= 0) error(_("seek is not relevant for loop connection")); return 0; /* if just asking, always at the beginning */ } -static Rconnection newtext(char *description, SEXP text) +static size_t raw_read(void *ptr, size_t size, size_t nitems, + Rconnection con) +{ +Rloopconn this = (Rloopconn)con->private; +if (this->cur + size*nitems > this->nchars) { + nitems = (this->nchars - this->cur)/size; + memcpy(ptr, this->data+this->cur, size*nitems); + this->cur = this->nchars; +} else { + memcpy(ptr, this->data+this->cur, size*nitems); + this->cur += size*nitems; +} +return nitems; +} + +static Rconnection newloop(char *description, SEXP data) { Rconnection new; new = (Rconnection) malloc(sizeof(struct Rconn)); -if(!new) error(_("allocation of text connection failed")); -new->class = (char *) malloc(strlen("textConnection") + 1); +if(!new) error(_("allocation of loop connection failed")); +
Re: [Rd] Questions about calls and formulas
Erich Neuwirth wrote: >>Try do.call like this: >> >>ff <- x ~ g*h >>do.call("substitute", list(ff, list(x = as.name("weight" >> > > > It is even more complicated. > All I know is that ff is a formula with an expression on the left hand > side. This expression needs to be replaced by "weights". > According to the documentation, substitute only handles > replacement of variables by something else, > and that is not enough in my case. That may make it simpler. For example: > ff <- x ~ g*h > ff[[2]] x > ff[[2]] <- as.name("weights") > ff weights ~ g * h If you know that ff is a formula with an expression on the left that you want to replace with "weights", then ff[[2]] <- as.name("weights") will work. (ff[[1]] is the tilde, ff[[3]] is the RHS. You'll probably want some sanity checks in your code to confirm this.) Duncan Murdoch __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Functions with the same name: best practices
Ok, here's another best practices question - let's say I'm writing a package and I want to use a function name that is already claimed by a function in the base R packages. For the sake of argument, let's pretend this function is for profiling the performance of a function (like Rprof for example), and so an obvious name that comes to mind is profile. This, of course, clashes with the built in profile for "investigating behavior of objective function near the solution represented by fitted." A little thinking and a quick survey of other packages reveal some possible solutions: * capitalise the function differently (eg. Profile) * use a prefix/suffic (eg. Rprof) * use a thesaurus * use namespaces (and rely on others to use namespaces correctly in their code/packages) What would you suggest? Thanks again, Hadley __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Functions with the same name: best practices
On 8/22/05, hadley wickham <[EMAIL PROTECTED]> wrote: > Ok, here's another best practices question - let's say I'm writing a > package and I want to use a function name that is already claimed by a > function in the base R packages. For the sake of argument, let's > pretend this function is for profiling the performance of a function > (like Rprof for example), and so an obvious name that comes to mind is > profile. This, of course, clashes with the built in profile for > "investigating behavior of objective function near the solution > represented by fitted." > > A little thinking and a quick survey of other packages reveal some > possible solutions: > > * capitalise the function differently (eg. Profile) > * use a prefix/suffic (eg. Rprof) > * use a thesaurus > * use namespaces (and rely on others to use namespaces correctly in > their code/packages) > > What would you suggest? > profile is a generic so if your function has the same purpose but for a different class you can just create a new method. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] TCITex and R
Several times my packages have fallen foul of the latex check at the uploading-to-CRAN stage, creating extra work for Kurt Hornik. I've never bothered trying to get latex working on my own packages (happy with vanilla help) but am told that "latex is the closest thing to a syntax checker for Rd files" and that I should set it up. Now, there is already a latex on my (Windows XP) system thanks to the program Scientific Word, which comes with TCITex. However, RCMD etc don't recognize this latex at the moment. Does anyone have any advice on what might be needed to make RCMD use SciWord's installation of TCITex-- paths, environment variables, etc etc? Various R docs recommend fptex or MikTex implementations of latex, but I'm a bit reluctant to put these on, primarily in case doing so somehow stuffs up the workings of Scientific Word in a way that I don't know enough to fix. In case it's not obvious already, I should add that I am blissfully ignorant about how latex works-- that's one of my reasons for using Scientific Word. Thanks for any advice Mark Mark Bravington CSIRO Mathematical & Information Sciences Marine Laboratory Castray Esplanade Hobart 7001 TAS ph (+61) 3 6232 5118 fax (+61) 3 6232 5012 mob (+61) 438 315 623 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Fetching Warning Messages
Hi, I read the help page and saw that warnings() actually prints the warning message and stores warning in top-level variable "last.warning". So it seems that it is almost impossible to access last warning from java code. I got another solution of fetching warning messages by storing warning messages in a file and reading the file later. This can be done by using sink() command, but before that options(warn=1) must be set. > Please read the help page on options("warn") and see what warnings() > does. (I am pretty sure you have asked this and been told before.) > > There should not be an object called last.warning in your example. > I read help page > On Mon, 22 Aug 2005, Nikhil Shah wrote: > > > Hi, > > > >I am facing one problem of fetching R warning messages in Java Code > > using Rserve. It is easier to trap R Error messages by using catching > > RSrvException. I came to know one way of fetching R Warning messages, i.e. > > using "withCallingHandlers", below is my Java Program, which uses > > withCallingHandlers of R : > > import org.rosuda.JRclient.*; > > > > ---RWarning.java--- > > class RWarning > > { > > public static void main(String args[]) > > { > > try > > { > > String hostName = null; > > hostName = args[0]; > > Rconnection c = new Rconnection(hostName); > > c.voidEval("lastWarning <- NULL"); > > c.voidEval("withCallingHandlers( > > {x<-sqrt(-9);y<-matrix(1:9,ncol=4);z<-sqrt(4)} , warning = function (w) { > > lastWarning <<- paste(lastWarning,as.character(w))})"); //This will generate > > warning message[sqrt(-9)], another warning message [ matrix(1:9,ncol=4) ] > > and successful completion [ sqrt(4) ] > >System.out.println(c.eval("z").asDouble()); > >System.out.println(c.eval("lastWarning").asString()); > >c.close(); > >System.out.println("DONE"); > > } > > catch(RSrvException e) > > { > > System.out.println("Error : " + e.getMessage()); > > e.printStackTrace(); > > } > > } > > } > > ---End Of RWarning.java--- > > > > Output of above program is (as expected) : > > > > 2.0 > > simpleWarning in sqrt(-9): NaNs produced > > simpleWarning: data length [9] is not a sub-multiple or multiple of the > > number of columns [4] in matrix > > > > DONE > > > > > > > > Now my query is that if there is any way of using warnings() function > > in Java Program to fetch all warnings. I used it in my program but returns > > me NULL instead of warning messages. I also used last.warning but it Java > > Program gives an error saying that last.warning object is not found. I have > > pasted both the java code below : > > > > This is the java program that I have written to use "last.warning" object of > > R. Please explain me where the error could be. > > > > Code of RWarning1.java > > > > import org.rosuda.JRclient.*; > > > > class RWarning1 > > { > > public static void main(String args[]) > > { > >try > >{ > > String hostName = null; > > hostName = args[0]; > > Rconnection c = new Rconnection(hostName); > > System.out.println(c.eval("x<-sqrt(-9)").asString()); > > System.out.println(c.eval("last.warning").asString()); > > c.close(); > > System.out.println("DONE"); > >} > >catch(RSrvException e) > >{ > > System.out.println("Error : " + e.getMessage()); > > e.printStackTrace(); > >} > > } > > } > > End of code of RWarning1.java-- > > > > output of RWarning1.class > > > > null > > Error : Request return code: 127 [request status: Error (127)] > > org.rosuda.JRclient.RSrvException: Request return code: 127 [request status: > > Err > > or (127)] > >at org.rosuda.JRclient.Rconnection.eval(Rconnection.java:190) > >at RWarning.main(RWarning.java:13) > > > > In other words, when I use "last.warning" in eval method, I simply get an > > exception, instead of value of last.warning. > > > > > > Below is the java code of using warnings() function. > > > > Code of RWarning2.java > > > > import org.rosuda.JRclient.*; > > > > class RWarning2 > > { > > public static void main(String args[]) > > { > > try > > { > >String hostName = null; > >hostName = args[0]; > >Rconnection c = new Rconnection(hostName); > >System.out.println(c.eval("x<-sqrt(-9)").asString()); > > > > System.out.println(c.eval("paste(capture.output(warnings()),collapse='\n')") > > .asString()); > >c.close(); > >System.out.println("DONE"); > > } > > catch(RSrvException e) > > { > >System.out.println("Error : " + e.getMessage()); > >e.printStackTrace(); > > } > > } > > } > > End of code of RWarning2.java-- > > output of RWarning2.class > > > > null > > NULL > > DONE > > > > > > Please let me know where I am making m
Re: [Rd] Functions with the same name: best practices
It depends on the example, as you might guess. profile() is a generic function in stats. Namespaces are not going to help there, as it is normally called by users (it is also called by some confint() methods, and that will be protected by namespaces). For functions intended to be used by end-users, I think there is little choice but to have distinct names. For other functions, you would not need to export them from the namespace of your package, and then probably the nameclash would be of little consequence. However, even there beware of examples like Adai's with 'df', where model.frame() found that object in the package rather than in his workspace. On Mon, 22 Aug 2005, hadley wickham wrote: > Ok, here's another best practices question - let's say I'm writing a > package and I want to use a function name that is already claimed by a > function in the base R packages. For the sake of argument, let's > pretend this function is for profiling the performance of a function > (like Rprof for example), and so an obvious name that comes to mind is > profile. This, of course, clashes with the built in profile for > "investigating behavior of objective function near the solution > represented by fitted." > > A little thinking and a quick survey of other packages reveal some > possible solutions: > > * capitalise the function differently (eg. Profile) > * use a prefix/suffic (eg. Rprof) > * use a thesaurus > * use namespaces (and rely on others to use namespaces correctly in > their code/packages) > > What would you suggest? > > Thanks again, > > Hadley > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > > -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel