Lennart.Borgman@astrazeneca.com
2004-Feb-10 13:27 UTC
[R] The ttest.c example in R under MS Windows
We are trying to compile and run the ttest.c example that comes with R (in C:\Program Files\R\rw1081\src\library\windlgs\src\ttest.c). After compiling it with MS Visual C++ we load the DLL with dyn.load. So far it seems good, but when we try to call it from R (after running C:\Program Files\R\rw1081\src\library\windlgs\R\windlgs.R) R crashes. We have tried changing the exports from DLL but have failed so far. Since I have a guy helping me who is fluent in MS Visual C++ I believe we are missing something crucial. Have anyone compiled and used the example above using MS Visual C++? Has anyone done this using the gcc (or Mingw) compiler on MS Windows? I would be very glad to find a complete example for compiling under MS Windows. - Lennart
On Tue, 10 Feb 2004 14:27:21 +0100, Lennart.Borgman at astrazeneca.com wrote :>We are trying to compile and run the ttest.c example that comes with R (in >C:\Program Files\R\rw1081\src\library\windlgs\src\ttest.c). After compiling >it with MS Visual C++ we load the DLL with dyn.load. > >So far it seems good, but when we try to call it from R (after running >C:\Program Files\R\rw1081\src\library\windlgs\R\windlgs.R) R crashes. > >We have tried changing the exports from DLL but have failed so far. Since I >have a guy helping me who is fluent in MS Visual C++ I believe we are >missing something crucial. Have anyone compiled and used the example above >using MS Visual C++? Has anyone done this using the gcc (or Mingw) compiler >on MS Windows? > >I would be very glad to find a complete example for compiling under MS >Windows.There's some general information about this sort of thing on my web page, <http://www.stats.uwo.ca/faculty/murdoch/software/compilingDLLs/>. The readme.packages file contains specific instructions about VC++, but they may be out of date: I use gcc, and Brian Ripley (who wrote those instructions) doesn't use Windows as much as he used to.>From the symptoms ("when we call it R crashes"), my guess would be aproblem with the calling convention, as described on my web page. You need to make sure your exports use the C calling convention, not stdcall. I don't know how to do that in VC++, but presumably your fluent helper would. If you do find what's wrong and it's a case of our documentation being out of date or incomplete, please write up a description of what works instead. This could be incorporated into readme.packages or put up on my web page. Duncan Murdoch
Thanks to everybody who answered my question. Here are the suggestion for completion sake of the archives. from John Fox @ Mcmaster.ca lo <- try(nls(y~y0+a/(1+(x/x0)^b),start=list(y0=0.1,a=a0,x0=x00,b=-8.1))) beta[i] <- if (class(lo) == "try-error") NA else lo$m$getPars()[4] from Peter Dalgaard @ biostat.ku.dk Just check the return value from try: beta[i] <- if(inherits(try(.....),"try-error")) NA else lo$etc... from Thomas Lumley @ u.washington.edu You want either both assignments inside the try() try({ lo<-nls(....) beta[i]<-lo$m$getPars(4) }) or both outside lo<- try(nls(....)) if (inherits(lo,"try-error")) beta[i]<-NA else beta[i]<-lo$m$getPars()[4] from Sundar Dorai-Raj @ pdf.com if (inherits(lo,"try-error")) beta[i]<-NA else beta[i]<-lo$m$getPars()[4] also from Andrej Kveder @ zrc-sazu.si; Patric Burns @ pburns.seanet.com Hadley Wickham @ auckland.ac.nz; from Douglas Bates @ stat.wisc.edu Check the function nlsList in package nlme. It does something very like what you want to do. It is not a good idea to use lo$m$getPars() directly. It is better to use the generic function, which in this case is coef(), as in coef(lo)[4] On Mon, 09 Feb 2004 14:30:07 -0500 "r.ghezzo" <heberto.ghezzo at mcgill.ca> wrote:>> Hello, I have a program with this section: >> .. >> for(i in 1:20){ >> lo <- >> nls(y~y0+a/(1+(x/x0)^b),start=list(y0=0.1,a=a0,x0=x00,b=-8.1)) >> beta[i] <- lo$m$getPars()[4] >> } >> .. >> If the fit works this is OK but if the fit fails, the whole program >> fails so: >> .. >> for(i in 1:20){ >> try(lo <- >> nls(y~y0+a/(1+(x/x0)^b),start=list(y0=0.1,a=a0,x0=x00,b=-8.1))) >> beta[i] <- lo$m$getPars()[4] >> } >> .. >> but the try catches the error in nls and beta[i] gets assigned >> beta[i-1] from the previous loop. This is bad but no so bad as it can >> be checked, >> Now in some cases the error is in i=1 and the program stops!! >> is there a way to set lo$m$getPars() to zero before the call? >> I tried to understand the use of tryCatch() but frankly it is above >> me. Sorry >> Thanks for any help >> Heberto Ghezzo >> Meakins-Christie Labs >> >>
Works just fine for me with the recommended compilers and tools. Here's a transcript of the build: c:\tools\R-1.8.1\src\gnuwin32>Rcmd install windlgs ---------- Making package windlgs ------------ adding build stamp to DESCRIPTION making DLL ... making ttest.d from ttest.c gcc -Ic:/tools/R-1.8.1/src/include -Wall -O2 -Ic:/tools/R-1.8.1/src/gnuwin32/ graphapp -c ttest.c -o ttest.o ar cr windlgs.a *.o ranlib windlgs.a windres --include-dir c:/tools/R-1.8.1/src/include -i windlgs_res.rc -o windlgs _res.o gcc --shared -s -o windlgs.dll windlgs.def windlgs.a windlgs_res.o -Lc:/tools /R-1.8.1/src/gnuwin32 -lg2c -lR ... DLL made installing DLL installing R files installing man source files installing indices installing help >>> Building/Updating help pages for package 'windlgs' Formats: text html latex example menu.ttest text html latex example >>> Building/Updating help pages for package 'windlgs' Formats: chm menu.ttest chm Microsoft HTML Help Compiler 4.74.8702 Compiling c:\tools\R-1.8.1\src\gnuwin32\windlgs\chm\windlgs.chm Compile time: 0 minutes, 2 seconds 2 Topics 4 Local links 0 Internet links 1 Graphic Created c:\tools\R-1.8.1\src\gnuwin32\windlgs\chm\windlgs.chm, 22,531 bytes Compression increased file by 8,709 bytes. adding MD5 sums And here's the test:> library(windlgs)To remove the Statistics menu use del.ttest()> x <- runif(10) > y <- runif(20)[click on `Statistics' from the menu, choose `ttest:1' and fill in.]> menu.ttest()Welch Two Sample t-test data: x and y t = 2.1473, df = 22.03, p-value = 0.04303 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 0.007352435 0.422008138 sample estimates: mean of x mean of y 0.6706490 0.4559688 Andy> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of > Lennart.Borgman at astrazeneca.com > Sent: Tuesday, February 10, 2004 8:27 AM > To: r-help at stat.math.ethz.ch > Subject: [R] The ttest.c example in R under MS Windows > > > We are trying to compile and run the ttest.c example that > comes with R (in > C:\Program Files\R\rw1081\src\library\windlgs\src\ttest.c). > After compiling > it with MS Visual C++ we load the DLL with dyn.load. > > So far it seems good, but when we try to call it from R (after running > C:\Program Files\R\rw1081\src\library\windlgs\R\windlgs.R) R crashes. > > We have tried changing the exports from DLL but have failed > so far. Since I > have a guy helping me who is fluent in MS Visual C++ I believe we are > missing something crucial. Have anyone compiled and used the > example above > using MS Visual C++? Has anyone done this using the gcc (or > Mingw) compiler > on MS Windows? > > I would be very glad to find a complete example for compiling under MS > Windows. > > > - Lennart > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}
Lennart.Borgman@astrazeneca.com
2004-Feb-11 16:24 UTC
[R] The ttest.c example in R under MS Windows
Thank you Andy, and thank you to all others who responded. I downloaded the tools and the compiler (though I used MSYS from the MINGW site, which seems to have the desired tools). From the bash shell that comes with MSYS I ran the commands in readme.packages: $ cd R_HOME/src/gnuwin32 $ make libR.a libRblas.a They seemed to work fine. Then I believe I am missing something crucial. I found a directory windlgs in the C:\Program Files\R\rw1081\src\library directory. So I cd-ed to this and tried to run the install command (again from the bash shell where the tools are in the path): $ rcmd install windlgs make: *** No rule to make target `Files/R/rw1081/src/library'. Stop. *** Installation of windlgs failed *** What is missing here? - Lennart -----Original Message----- From: Liaw, Andy [mailto:andy_liaw at merck.com] Sent: 10 februari 2004 15:57 To: Borgman, Lennart; r-help at stat.math.ethz.ch Subject: RE: [R] The ttest.c example in R under MS Windows Works just fine for me with the recommended compilers and tools. Here's a transcript of the build: c:\tools\R-1.8.1\src\gnuwin32>Rcmd install windlgs ---------- Making package windlgs ------------ adding build stamp to DESCRIPTION making DLL ... making ttest.d from ttest.c gcc -Ic:/tools/R-1.8.1/src/include -Wall -O2 -Ic:/tools/R-1.8.1/src/gnuwin32/ graphapp -c ttest.c -o ttest.o ar cr windlgs.a *.o ranlib windlgs.a windres --include-dir c:/tools/R-1.8.1/src/include -i windlgs_res.rc -o windlgs _res.o gcc --shared -s -o windlgs.dll windlgs.def windlgs.a windlgs_res.o -Lc:/tools /R-1.8.1/src/gnuwin32 -lg2c -lR ... DLL made installing DLL installing R files installing man source files installing indices installing help >>> Building/Updating help pages for package 'windlgs' Formats: text html latex example menu.ttest text html latex example >>> Building/Updating help pages for package 'windlgs' Formats: chm menu.ttest chm Microsoft HTML Help Compiler 4.74.8702 Compiling c:\tools\R-1.8.1\src\gnuwin32\windlgs\chm\windlgs.chm Compile time: 0 minutes, 2 seconds 2 Topics 4 Local links 0 Internet links 1 Graphic Created c:\tools\R-1.8.1\src\gnuwin32\windlgs\chm\windlgs.chm, 22,531 bytes Compression increased file by 8,709 bytes. adding MD5 sums And here's the test:> library(windlgs)To remove the Statistics menu use del.ttest()> x <- runif(10) > y <- runif(20)[click on `Statistics' from the menu, choose `ttest:1' and fill in.]> menu.ttest()Welch Two Sample t-test data: x and y t = 2.1473, df = 22.03, p-value = 0.04303 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: 0.007352435 0.422008138 sample estimates: mean of x mean of y 0.6706490 0.4559688 Andy> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of > Lennart.Borgman at astrazeneca.com > Sent: Tuesday, February 10, 2004 8:27 AM > To: r-help at stat.math.ethz.ch > Subject: [R] The ttest.c example in R under MS Windows > > > We are trying to compile and run the ttest.c example that > comes with R (in > C:\Program Files\R\rw1081\src\library\windlgs\src\ttest.c). > After compiling > it with MS Visual C++ we load the DLL with dyn.load. > > So far it seems good, but when we try to call it from R (after running > C:\Program Files\R\rw1081\src\library\windlgs\R\windlgs.R) R crashes. > > We have tried changing the exports from DLL but have failed > so far. Since I > have a guy helping me who is fluent in MS Visual C++ I believe we are > missing something crucial. Have anyone compiled and used the > example above > using MS Visual C++? Has anyone done this using the gcc (or > Mingw) compiler > on MS Windows? > > I would be very glad to find a complete example for compiling under MS > Windows. > > > - Lennart > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >---------------------------------------------------------------------------- -- Notice: This e-mail message, together with any attachments,...{{dropped}}