[Rd] Strange number produced by dnorm
Hi All, I just started to learn compiling C codes for R usage, and got a problem when I was playing with my 'hello world' code. #include #include #include SEXP test( ) { double x; x=dnorm(1.0,0.0,1.0,1); printf(" x value is: %d \n",x); return(R_NilValue); } I got the result :x value is: -466460838 Could someone explain to me what was wrong here ? Thanks a lot. tong __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Strange number produced by dnorm
Having a hard time picking up C :( Thanks a lot for all your time . tong - Original Message - From: Peter Dalgaard <[EMAIL PROTECTED]> Date: Wednesday, April 4, 2007 12:44 am Subject: Re: [Rd] Strange number produced by dnorm To: Tong Wang <[EMAIL PROTECTED]> Cc: R-devel > Tong Wang wrote: > > Hi All, > > I just started to learn compiling C codes for R usage, and > got a problem when I was playing with my 'hello world' code. > > > > #include > > #include > > #include > > > > SEXP test( ) { > > double x; > > x=dnorm(1.0,0.0,1.0,1); > > printf(" x value is: %d \n",x); > > return(R_NilValue); > > } > > > >I got the result :x value is: -466460838 > > > > Could someone explain to me what was wrong here ? > > > > > Wrong printf format. "%d" is for integers. > > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] How to debug C code running in R
Hi, I am in the situation where I could get my code run correctly under GNU C, but it produced different (strange) results while running in R . ( I use .C to call the function). May I get some general advice on how could I do step by step debug of source code in R ? Thanks __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] To use breaktodebugger(), which file should I include in C code?
Hi, I have tried several headers in RHOME/include , but none of them seemed to work . Thanks for your help. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Problem with rnorm ?
Hi, I couldn't get the rnorm() work right in C, for example, the following code produce strange results. #include #include int main(void){ double x[3]; for(int i=0;i<3;i++) x[i]=rnorm(0,1); printf("%lf,%lf,%lf",x[0],x[1],x[2]); return 0; } output : -8.773321,-8.773321,-8.773321 compiling script: gcc -std=gnu99 -Wall -IC:/PROGRA~1/R/R-24~1.1/include test.c -LC:/PROGRA~1/R/R-24~1.1/bin -lR -o test Could someone tell me what's wrong with my code ? Thanks a lot. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Problem with rnorm ?
It's working , Thanks a lot !!! tong - Original Message - From: Prof Brian Ripley <[EMAIL PROTECTED]> Date: Saturday, May 12, 2007 4:27 am Subject: Re: [Rd] Problem with rnorm ? To: Tong Wang <[EMAIL PROTECTED]> Cc: R-devel > 1) You are linking an executable against -lR. You can't do that as > here,for R is never initialized (and I very much doubt you will be > able to > give a reference that recommended you to do that). You need to > link > against standalone libRmath, or start up R properly if you really > need R. > > 2) The arguments to rnorm() are doubles, not integers: did you not > get a > warning? I would expect automatic conversion to occur, but it is > better > to get this right. > > On Fri, 11 May 2007, Tong Wang wrote: > > > Hi, > >I couldn't get the rnorm() work right in C, for example, the > following code produce strange results. > > > > #include > > #include > > > > int main(void){ > > double x[3]; > > for(int i=0;i<3;i++) x[i]=rnorm(0,1); > > printf("%lf,%lf,%lf",x[0],x[1],x[2]); > > return 0; > > } > > > > output : -8.773321,-8.773321,-8.773321 > > compiling script: gcc -std=gnu99 -Wall -IC:/PROGRA~1/R/R- > 24~1.1/include test.c -LC:/PROGRA~1/R/R-24~1.1/bin -lR -o test > > > > Could someone tell me what's wrong with my code ? Thanks a lot. > > > > __ > > 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] Strange behavior of debugger
Hi, All: I had some trouble debugging C source dynamically loaded into R , when I issued N in gdb(or insight) , the debugger, instead of moving downward step by step, jumped to strange positions (upward, downward, one step, a few steps away). To enter the debugger, I issued gdb(insight) Rgui.exe in Cygwin and add this line : asm("int $3"); to my C code. After entering R, I did something like: dyn.load("mypath/mycode.dll") , then out <- .C("myfun", arg1=as.numeric(a),..) The C files are compiled with:R CMD SHLIB -d myfile.c I am using Win XP + Cygwin, and I have a binary version and a cygwin compiled version of R-2.4.1 installed. This same behavior show up in both installations. One thing is, even though I set the evn DEBUG as T when built R from sourse in Cygwin, the Rgui.exe I got doesn't seem to contain debug info. (although R.exe does) , I am not sure if this means I did something wrong. Appreciate any help. tong __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] set_seed
Hi, All: It seemed set_seed is usable only when Rmath is used as a standalone library, then what should I use when I need to link to R.dll. Thanks . tong __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] set_seed
In this case, how do I choose numbers to make sure set_seed(n1,n2) and set.seed(n) produce the same result ? I am asking because my C code worked correctly if I compile it to produce .exe file and ran it , but it gave strange results if it is compiled to .dll file and dynamically loaded into R and call with .C( ). To debug, I need to let them produce the same random number under two different situation so I can tell what is wrong in R. Thanks a lot. - Original Message - From: Prof Brian Ripley <[EMAIL PROTECTED]> Date: Monday, May 14, 2007 9:40 pm Subject: Re: [Rd] set_seed To: Tong Wang <[EMAIL PROTECTED]> Cc: R-devel > On Mon, 14 May 2007, Tong Wang wrote: > > > Hi, All: > > > It seemed set_seed is usable only when Rmath is used as a > standalone > > library, then what should I use when I need to link to R.dll. > > When you link to R.dll you are running R, so you can call > set.seed() via > eval or via do_setseed. > > -- > 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] Debug with set.seed()
HI, all I am debugging an R code with dynamically loaded function in it. It seems set.seed(n) does not give me the same random draws every time. Could somebody tell me what I should do to get the same outcome verytime ? I am not sure what infomation is relevent to this question , the following is a really scatchy description of the code I wrote.I am using the R-2.4.1 built under Cygwin. OS is WinXP. Thanks a lot for any help. Myfunction<-function(...) { ... drawsomething<-function(){ out<- .C( "drawit"...) var <<- out$var # assign the outputs} ... for( i in 1 : iter) { . drawsomething() .. } reture( var.stor ) #return stored result } __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] linking problem
Hi, All I got the following message while trying to compile a file and link it to some local libraries. I am sure that the path to local libs are given correctly, them why can't the linker find them ? These libs are static ones, like libBOOMdebug.a , is this a problem ? Do I need to convert all of them to DLL's ? Is there an easy way to this. I am not quite familiar with this, I would appreciate it if your advice could be a little detailed. Thanks a lot in advance. $ R CMD SHLIB -d dmvtnorm.cpp making dmvtnorm.d from dmvtnorm.c gcc -IC:/cygwin/home/owner/R-2.4.1/include -I/home/owner/BOOM2/src -gdwarf-2 -Wall -O0 -std=gnu99 -c dmvt norm.c -o dmvtnorm.o g++ -shared -o dmvtnorm.dll dmvtnorm.def dmvtnorm.o -LC:/cygwin/home/owner/R-2.4.1/bin -L/home/owner/BOO M2 -lR -lBOOMdebug -llapack -lf77blas -lcblas -latlas -lg2c -lboost_program_options-gcc -lboost_filesyste m-gcc -lboost_signals-gcc -lm c:\programs\Rtools\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lBOOMdebug collect2: ld returned 1 exit status make: *** [dmvtnorm.dll] Error 1 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel