Re: [Rd] problem with findFun call from embedded R
Joe Conway wrote: > I was debugging a problem reported to me regarding PL/R, and found that > I can duplicate it using only R sources. It might be characterized as > possibly a misuse of the findFun() function, but I leave that for the R > devel experts to decide. > > The below results are all with R-2.5.1 (I can't seem to download > r-patched at the moment, but didn't see anything in the 2.5.1-patched > release notes indicating this issue had been noticed) on Fedora Core 6 > x86_64 (also duplicated with R-2.5.0 on FC7 i386). > > Steps to reproduce: > 8< > configure, make, make install from source tree > cd tests/Embedding/ > make RNamedCall > ./RNamedCall #works as expected > mv foo.R foo.R.orig > ./RNamedCall #segfaults > 8< > > output: > 8< > Error in file(file, "r", encoding = encoding) : > unable to open connection > In addition: Warning message: > cannot open file 'foo.R', reason 'No such file or directory' in: > file(file, "r", encoding = encoding) > Error: could not find function "foo" > > *** caught segfault *** > address (nil), cause 'memory not mapped' > > Possible actions: > 1: abort (with core dump, if enabled) > 2: normal R exit > 3: exit R without saving workspace > 4: exit R saving workspace > Selection: 1 > aborting ... > Segmentation fault > 8< > > The problem comes from RNamedCall starting at line 54: > 8< >fun = findFun(install("foo"), R_GlobalEnv); >if(fun == R_NilValue) { > fprintf(stderr, "No definition for function foo. > Source foo.R and save the session.\n"); >UNPROTECT(1); >exit(1); >} > 8< > > If foo.R was not found and never sourced, meaning that the object "foo" > does not exist, findFun never returns. Instead the segfault occurs at > line 719 in errors.c at the LONGJMP statement. Setting a breakpoint at > erros.c:719, the backtrace looks like this (will wrap poorly): > > 8< > Breakpoint 2, jump_to_top_ex (traceback=TRUE, tryUserHandler=TRUE, > processWarnings=TRUE, resetConsole=TRUE, > ignoreRestartContexts=FALSE) at errors.c:719 > 719 LONGJMP(R_ToplevelContext->cjmpbuf, 0); > (gdb) bt > #0 jump_to_top_ex (traceback=TRUE, tryUserHandler=TRUE, > processWarnings=TRUE, resetConsole=TRUE, > ignoreRestartContexts=FALSE) at errors.c:719 > #1 0x2ab77e5d in verrorcall_dflt (call=0x609d78, > format=0x2ace4a4d "%s", ap=0x7fffa13a94c0) > at errors.c:516 > #2 0x2ab7814a in Rf_errorcall (call=0x609d78, > format=0x2ace4a4d "%s") at errors.c:551 > #3 0x2ab78347 in Rf_error (format=0x2ace42da "could not > find function \"%s\"") at errors.c:578 > #4 0x2ab708e5 in Rf_findFun (symbol=0xc64f20, rho=0x649fa0) at > envir.c:1244 > #5 0x00400e0c in bar1 () at RNamedCall.c:54 > #6 0x00400d59 in main (argc=1, argv=0x7fffa13ab838) at > RNamedCall.c:16 > 8< > > And then stepping into line 719 generates the segfault: > 8< > (gdb) s > > Program received signal SIGSEGV, Segmentation fault. > 0x2ab701ce in Rf_findVar (symbol=0x6c12b8, rho=0x0) at envir.c:998 > 998 if (TYPEOF(rho) == NILSXP) > 8< > > I believe this is happening because findFun() was not executed inside a > valid context, and therefore R_ToplevelContext->cjmpbuf is invalid. > > My question is -- is the above an abuse of findFun() by RNamedCall.c > (meaning I should avoid the same pattern)? Or maybe it should be wrapped > in something similar to R_ToplevelExec? Yes, when one embeds R, findFun() will call error() which causes the longjmp() to the top level, so the embedding application shouldn't use findFun(). Here's what I've written for the next version of RApache. Note that it's behavior is slightly different than the original findFun(), in that it doesn't search the enclosing environments. (Also, comments welcome as the implementation is based on the original, and I'm unsure if promise evaluation is needed.) /* This one doesn't longjmp when function not found */ static SEXP MyfindFun(SEXP symb, SEXP envir){ SEXP fun; SEXPTYPE t; fun = findVar(symb,envir); t = TYPEOF(fun); /* eval promise if need be */ if (t == PROMSXP){ int error=1; fun = R_tryEval(fun,envir,&error); if (error) return R_UnboundValue; t = TYPEOF(fun); } if (t == CLOSXP || t == BUILTINSXP || t == BUILTINSXP || t == SPECIALSXP) return fun; return R_UnboundValue; } > > == > > On a related note, I found during my PL/R debugging that the segfault > was causing the same console based, interactive, "*** caught segfault > ***" logic to execute. I was able to confirm that R_Interactive was set > to TRUE i
Re: [Rd] data messed up by read.table ? (PR#9779)
On Thu, 5 Jul 2007 [EMAIL PROTECTED] wrote: > Following Michael J. Crawley "Statistical Computing" on page 9 the worms.txt > is > required. After downloading it from the book's supporting website, which is > http://www.bio.ic.ac.uk/research/mjcraw/statcomp/data/ I visually check the > data > against the book and they look identical. Then I do a read.table as suggested: > worms<-read.table("C:/Programme/R/R-2.5.0/Data/Worms.txt", header = T). Add the argument quote="" or quote="\"" to the call to read.table() so the apostrophes in the file are not taken to be quotes. > Typing "worms" to see the data, it's no longer the same: Four lines have been > added to the beginning of the file. One is the header line and three lines are > from further down in the file, i.e. lines 10,11 and 12 in reverse order. > Please look at a copy at the end of this mail. If the first four lines weren't > there, the data would be o.k. I tried different parameter settings in > read.table > but couldn't obtain any improvement. > > Please let me know, how I can correct this. > > Best regards > > Joerg > > > worms<-read.table("C:/Programme/R/R-2.5.0/Data/Worms.txt", header = T) > > worms > Field.Name Area Slope Vegetation Soil.pH Damp Worm.density > 1 Oak.Mead 3.1 2 Grassland 3.9F2 > 2 Church.Field 3.5 3 Grassland 4.2F3 > 3Ashurst 2.1 0 Arable 4.8F4 > 4 Field.Name Area Slope Vegetation Soil.pH Damp Worm.density > 5 Nash's.Field 3.611 Grassland 4.1F4 > 6 Silwood.Bottom 5.1 2 Arable 5.2F7 > 7 Nursery.Field 2.8 3 Grassland 4.3F2 > 8Rush.Meadow 2.4 5 Meadow 4.9T5 > 9 Gunness'.Thicket 3.8 0 Scrub 4.2F6 > 10 Oak.Mead 3.1 2 Grassland 3.9F2 > 11 Church.Field 3.5 3 Grassland 4.2F3 > 12 Ashurst 2.1 0 Arable 4.8F4 > 13 The.Orchard 1.9 0Orchard 5.7F9 > 14 Rookery.Slope 1.5 4 Grassland 5T7 > 15 Garden.Wood 2.910 Scrub 5.2F8 > 16 North.Gravel 3.3 1 Grassland 4.1F1 > 17 South.Gravel 3.7 2 Grassland 4F2 > 18 Observatory.Ridge 1.8 6 Grassland 3.8F0 > 19Pond.Field 4.1 0 Meadow 5T6 > 20 Water.Meadow 3.9 0 Meadow 4.9T8 > 21 Cheapside 2.2 8 Scrub 4.7T4 > 22Pound.Hill 4.4 2 Arable 4.5F5 > 23Gravel.Pit 2.9 1 Grassland 3.5F1 > 24 Farm.Wood 0.810 Scrub 5.1T3 Bill Dunlap Insightful Corporation bill at insightful dot com 360-428-8146 "All statements in this message represent the opinions of the author and do not necessarily reflect Insightful Corporation policy or position." __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] data messed up by read.table ? (PR#9779)
On Thursday 05 July 2007 7:00:46 am [EMAIL PROTECTED] wrote: > Full_Name: Joerg Rauh > Version: 2.5.0 > OS: Windows 2000 > Submission from: (NULL) (84.168.226.163) > > > Following Michael J. Crawley "Statistical Computing" on page 9 the > worms.txt is required. After downloading it from the book's supporting > website, which is http://www.bio.ic.ac.uk/research/mjcraw/statcomp/data/ I > visually check the data against the book and they look identical. Then I do > a read.table as suggested: > worms<-read.table("C:/Programme/R/R-2.5.0/Data/Worms.txt", header = T). > I see the same effect on 2.5.0 and 2.5.1 running on Linux. However, the following line reads the data correctly: read.table('worms.txt', header=TRUE, quote="\"") Thus the problem is likely because of single quotes in the Field.Name column, perhaps a single quote character was added to the list of defaults since the book was released. best Vladimir Dergachev __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] data messed up by read.table ? (PR#9779)
Full_Name: Joerg Rauh Version: 2.5.0 OS: Windows 2000 Submission from: (NULL) (84.168.226.163) Following Michael J. Crawley "Statistical Computing" on page 9 the worms.txt is required. After downloading it from the book's supporting website, which is http://www.bio.ic.ac.uk/research/mjcraw/statcomp/data/ I visually check the data against the book and they look identical. Then I do a read.table as suggested: worms<-read.table("C:/Programme/R/R-2.5.0/Data/Worms.txt", header = T). Typing "worms" to see the data, it's no longer the same: Four lines have been added to the beginning of the file. One is the header line and three lines are from further down in the file, i.e. lines 10,11 and 12 in reverse order. Please look at a copy at the end of this mail. If the first four lines weren't there, the data would be o.k. I tried different parameter settings in read.table but couldn't obtain any improvement. Please let me know, how I can correct this. Best regards Joerg > worms<-read.table("C:/Programme/R/R-2.5.0/Data/Worms.txt", header = T) > worms Field.Name Area Slope Vegetation Soil.pH Damp Worm.density 1 Oak.Mead 3.1 2 Grassland 3.9F2 2 Church.Field 3.5 3 Grassland 4.2F3 3Ashurst 2.1 0 Arable 4.8F4 4 Field.Name Area Slope Vegetation Soil.pH Damp Worm.density 5 Nash's.Field 3.611 Grassland 4.1F4 6 Silwood.Bottom 5.1 2 Arable 5.2F7 7 Nursery.Field 2.8 3 Grassland 4.3F2 8Rush.Meadow 2.4 5 Meadow 4.9T5 9 Gunness'.Thicket 3.8 0 Scrub 4.2F6 10 Oak.Mead 3.1 2 Grassland 3.9F2 11 Church.Field 3.5 3 Grassland 4.2F3 12 Ashurst 2.1 0 Arable 4.8F4 13 The.Orchard 1.9 0Orchard 5.7F9 14 Rookery.Slope 1.5 4 Grassland 5T7 15 Garden.Wood 2.910 Scrub 5.2F8 16 North.Gravel 3.3 1 Grassland 4.1F1 17 South.Gravel 3.7 2 Grassland 4F2 18 Observatory.Ridge 1.8 6 Grassland 3.8F0 19Pond.Field 4.1 0 Meadow 5T6 20 Water.Meadow 3.9 0 Meadow 4.9T8 21 Cheapside 2.2 8 Scrub 4.7T4 22Pound.Hill 4.4 2 Arable 4.5F5 23Gravel.Pit 2.9 1 Grassland 3.5F1 24 Farm.Wood 0.810 Scrub 5.1T3 > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] data messed up by read.table ? (PR#9779)
[EMAIL PROTECTED] wrote: > Full_Name: Joerg Rauh > Version: 2.5.0 > OS: Windows 2000 > Submission from: (NULL) (84.168.226.163) > > > Following Michael J. Crawley "Statistical Computing" on page 9 the worms.txt > is > required. After downloading it from the book's supporting website, which is > http://www.bio.ic.ac.uk/research/mjcraw/statcomp/data/ I visually check the > data > against the book and they look identical. Then I do a read.table as suggested: > worms<-read.table("C:/Programme/R/R-2.5.0/Data/Worms.txt", header = T). > > Typing "worms" to see the data, it's no longer the same: Four lines have been > added to the beginning of the file. One is the header line and three lines are > from further down in the file, i.e. lines 10,11 and 12 in reverse order. > Please look at a copy at the end of this mail. If the first four lines weren't > there, the data would be o.k. I tried different parameter settings in > read.table > but couldn't obtain any improvement. > > Please let me know, how I can correct this. > > Best regards > > Joerg > > >> worms<-read.table("C:/Programme/R/R-2.5.0/Data/Worms.txt", header = T) >> worms >> > Field.Name Area Slope Vegetation Soil.pH Damp Worm.density > 1 Oak.Mead 3.1 2 Grassland 3.9F2 > 2 Church.Field 3.5 3 Grassland 4.2F3 > 3Ashurst 2.1 0 Arable 4.8F4 > 4 Field.Name Area Slope Vegetation Soil.pH Damp Worm.density > 5 Nash's.Field 3.611 Grassland 4.1F4 > 6 Silwood.Bottom 5.1 2 Arable 5.2F7 > 7 Nursery.Field 2.8 3 Grassland 4.3F2 > 8Rush.Meadow 2.4 5 Meadow 4.9T5 > 9 Gunness'.Thicket 3.8 0 Scrub 4.2F6 > 10 Oak.Mead 3.1 2 Grassland 3.9F2 > 11 Church.Field 3.5 3 Grassland 4.2F3 > 12 Ashurst 2.1 0 Arable 4.8F4 > 13 The.Orchard 1.9 0Orchard 5.7F9 > 14 Rookery.Slope 1.5 4 Grassland 5T7 > 15 Garden.Wood 2.910 Scrub 5.2F8 > 16 North.Gravel 3.3 1 Grassland 4.1F1 > 17 South.Gravel 3.7 2 Grassland 4F2 > 18 Observatory.Ridge 1.8 6 Grassland 3.8F0 > 19Pond.Field 4.1 0 Meadow 5T6 > 20 Water.Meadow 3.9 0 Meadow 4.9T8 > 21 Cheapside 2.2 8 Scrub 4.7T4 > 22Pound.Hill 4.4 2 Arable 4.5F5 > 23Gravel.Pit 2.9 1 Grassland 3.5F1 > 24 Farm.Wood 0.810 Scrub 5.1T3 > Same thing happens on Linux. It appears to be the single quotes that mess things up. Using read.delim(), which is designed to read tab-delimitedfiles like this one, works as does setting quote="". __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] cor() and cor.test() (PR#9781)
Hello, I am trying to make a correlation matrix in R using cor() and also to get the p-value for each correlation using cor.test(). I can't get these commands to work. I'm getting errors like the following: cor(Pollution, Wet.days) Error in inherits(x, "data.frame") : Object "Wet.days" not found cor("Pollution", "Wet.days") Error in cor("Pollution", "Wet.days") : missing observations in cov/cor In addition: Warning messages: 1: NAs introduced by coercion 2: NAs introduced by coercion I know that "Wet.days" is there because when I type the name of the data set (Pollution) it appears. There are no missing values in the data set for there to be any NAs coerced. This is the example given in Mick Crawley's book on R with Pollution data so it should definitely work. Can you help me to get it working, please? Kristle -- Kristle Krichbaum Graduate Assistant Hudson Lab 208 Mueller Lab University Park, PA 16801 www.cidd.psu.edu [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] cor() and cor.test() (PR#9781)
The cor function does not know how to look inside of data frames (unless you give it the entire data frame as the only argument). If Pollution and Wet.days are columns of the data frame named Pollution (which I infer from your problem statement below) then you can do things like: > cor(Pollution$Pollution, Pollution$Wed.days) Or > cor( Pollution[ ,c('Pollution','Wet.days')] ) Or > with( Pollution, cor(Pollution, Wet.days) ) Or > attach(Pollution) > cor(Pollution, Wet.days) > detach() The last one may have problems since the data frame has the same name as the column. The with option is prefered to the last one anyways. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of > [EMAIL PROTECTED] > Sent: Thursday, July 05, 2007 1:49 PM > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Subject: [Rd] cor() and cor.test() (PR#9781) > > Hello, > > I am trying to make a correlation matrix in R using cor() and > also to get the p-value for each correlation using > cor.test(). I can't get these commands to work. I'm getting > errors like the following: > > cor(Pollution, Wet.days) > Error in inherits(x, "data.frame") : Object "Wet.days" not > found cor("Pollution", "Wet.days") Error in cor("Pollution", > "Wet.days") : missing observations in cov/cor In addition: > Warning messages: > 1: NAs introduced by coercion > 2: NAs introduced by coercion > > I know that "Wet.days" is there because when I type the name > of the data set > (Pollution) it appears. There are no missing values in the > data set for there to be any NAs coerced. This is the example > given in Mick Crawley's book on R with Pollution data so it > should definitely work. > > Can you help me to get it working, please? > Kristle > > -- > Kristle Krichbaum > Graduate Assistant > Hudson Lab > 208 Mueller Lab > University Park, PA 16801 > www.cidd.psu.edu > > [[alternative HTML version deleted]] > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Type on ?heatmap
In ?heatmap (of stats) of R v2.5.1 under the Note section is reads: "Unless Rowv = NA (or Colw = NA), the original rows and columns are reordered..." Typo: 'Colw' should be 'Colv'. /Henrik __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel