[Rd] package Geneland / Rgui under windows (PR#9964)
Full_Name: Gilles Guillot Version: 2.6.0 OS: windows XP professional Submission from: (NULL) (129.240.88.50) This sequence of command does not work in the R gui 2.6.0: library(Geneland) set.seed(1) data <- simdata(nindiv=200, coord.lim=c(0,1,0,1) , number.nuclei=5 , allele.numbers=rep(10,20), IBD=FALSE, npop=2, give.tess.grid=FALSE) geno <- data$genotypes coord <- t(data$coord.indiv) path.mcmc <- paste(tempdir(),"/",sep="") set.seed(1) mcmcFmodel(coordinates=coord, genotypes=geno, path.mcmc=path.mcmc, rate.max=10, delta.coord=0, npopmin=1, npopinit=5, npopmax=5, nb.nuclei.max=50, nit=500, thinning=1, freq.model="Dirichlet", varnpop=FALSE, spatial=TRUE) the call to mcmcFmodel freezes R The same sequence of command works in the R command line of R 2.6.0 and also in the R GUI of 2.5.1 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Calling C from Fortran
I would like to call C routines from Fortran under linux as suggested in section 5.6 of the "Writing R extensions" documentation. I'm familiar with Fortran but not with C. I understand the example provided in Fortran: subroutine testit() double precision normrnd, x call rndstart() x = normrnd() call dblepr("X was", 5, x, 1) call rndend() end but I don't understand the purpose of this C wrapper: #include void F77_SUB(rndstart)(void) { GetRNGstate(); } void F77_SUB(rndend)(void) { PutRNGstate(); } double F77_SUB(normrnd)(void) { return norm_rand(); } neither how I should compile it. Could anyone explain how I should compile and link the C and Fortran files above, and call the Fortran subroutine from R. Thanks, Gilles __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Calling C function from Fortran
Hi all, the example in the R doc and the hints from Shusong Jin , Ingmar Visser and Reid Huntsinger (thanks all three) refer to the case where the function does not have arguments. I'm still looking for a proper sequence of commands to call C functions with arguemnts from R. Imagine I want to evaluate the gamma function. I want to use the C function called by R. (I guess it is the one corresponding to the source code I found in the directory R-2.1.0/src/nmath/gamma.c of the source distribution). The following programs do not work (it returns fancy values) #include #include void F77_SUB(mygammac)(double x, double y) { y = gammafn(x); } subroutine mygammaf(x,y) double precision x,y call mygammac(x,y) end called in R through x <- 3 y <- -999 res <- .Fortran("mygammaf", as.double(x), as.double(y)) While changing the C code into #include #include void F77_SUB(mygammac)(double *x, double *y) { *y = gammafn(*x); } seems to work fine. But R-2.1.0/src/nmath/gamma.c does not need a pointer ? What is wrong whit he first set of lines ? What is the correct way to call the C function in R-2.1.0/src/nmath/gamma.c ? Thanks in advance Gilles __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Calling C from Fortran
Thanks for your reply. Am I write if I say that the wrapper shoul be double F77_SUB(mygammafn)(double *x) { return gammafn(*x); } instead of double F77_SUB(mygammafn)(double *x) { return gammafn(x); } the first does not compile. wrapper2.c: In function `mygammafn_': wrapper2.c:6: error: incompatible type for argument 1 of `Rf_gammafn' The second compiles and works fine. But still, I find it very strange as the C function gammafn actually called ( as I can see from /R-2.1.0/src/nmath/gamma.c) is not defined as double gammafn(double *x) but as double gammafn(double x) Am I missing something ? Gilles Le Mercredi 15 Juin 2005 17:06, vous avez écrit : > I actually deleted a part of my reply, dealing with exactly that. Sorry! > You need to declare the C wrapper to take a pointer to a double ("double > *") rather than a double. C passes by value whereas Fortran passes by > reference; in C you get this effect by passing a pointer to the value > (which is also a value). So you want > > double F77_SUB(mygammafn)(double *x) { return gammafn(x); } > > That should work; if not let me know and I'll look more carefully at > Fortran <-> C conventions. > > Reid Huntsinger > > -Original Message- > From: Gilles GUILLOT [mailto:[EMAIL PROTECTED] > Sent: Wednesday, June 15, 2005 3:50 AM > To: Huntsinger, Reid > Subject: Re: [Rd] Calling C from Fortran > > > Thanks Reid! > And now if I want to call a C function with arguments, > e.g. to compute the gamma function at x, > my C wrapper is: > > #include > #include > void F77_SUB(rndstart)(void) { GetRNGstate(); } > void F77_SUB(rndend)(void) { PutRNGstate(); } > double F77_SUB(normrnd)(void) { return norm_rand(); } > double F77_SUB(mygammafn)(double x) { return gammafn(x); } > > And my Fortran is: > subroutine testit() > implicit none > double precision normrnd, x, y, mygammafn > call rndstart() > x = dabs(normrnd()) > write(*,*) 'x=',x > call rndend() > > y = mygammafn(x) > write(*,*) 'y=',y > end > > And it does not work, all calls of testit return the same y value. > What is incorrect in my files ? > > > Gilles > > > > > > --- >--- Notice: This e-mail message, together with any attachments, contains > information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New > Jersey, USA 08889), and/or its affiliates (which may be known outside the > United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as > Banyu) that may be confidential, proprietary copyrighted and/or legally > privileged. It is intended solely for the use of the individual or entity > named on this message. If you are not the intended recipient, and have > received this message in error, please notify us immediately by reply > e-mail and then delete it from your system. > --- >--- -- _ Gilles GUILLOT INRA -Département Mathématiques et Informatique Appliquées Unité Mixte de Recherche INRA - INAPG - ENGREF Institut National Agronomique de Paris-Grignon 16, rue Claude Bernard 75231 Paris cedex 5 France phone 33 1 44 08 18 42 fax 33 1 44 08 16 66 http://www.inapg.fr/ens_rech/mathinfo/personnel/guillot/welcome.html __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] calling fortran functions CHOL and DPOTRF form Fortran
Hi all, I'm working out some Fortran code for which I want to compute the Choleski decomposition of a covariance matrix in Fortran. I tried to do it by two methods : 1) Calling the lapack function DPOTRF. I can see the source code and check that my call is correct, but it does not compile with: system("R CMD SHLIB ~/main.f") dyn.load("~/main.so") I get: Error in dyn.load(x, as.logical(local), as.logical(now)) : unable to load shared library [...] undefined symbol: dpotrf_ Could anyone point out how to compile with such a call to lapack? 2) Calling the Fortran function CHOL The previous combination of R CMD SHLIB and dyn.load compiles fine but I would like to see the source code of this function to check if my call is correct. I've not been able to find it in the R source distribution. Could anyone point the place of that file? Thanks in advance, Gilles -- _________ Gilles GUILLOT INRA -Département Mathématiques et Informatique Appliquées Unité Mixte de Recherche INRA - INAPG - ENGREF Institut National Agronomique de Paris-Grignon 16, rue Claude Bernard 75231 Paris cedex 5 France phone 33 1 44 08 18 42 fax 33 1 44 08 16 66 http://www.inapg.fr/ens_rech/mathinfo/personnel/guillot/welcome.html __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] pb with dyn.load
Hi, here are a couple of strange things happening with R.2.2.0 compiled under Mandrake-10.1 At the begining of the story I have segmentation fault using package RandomFields in conjuction with some Fortran code of mine loaded with dyn.load. One of my fortran programs contains a subroutine named fstat Trying to trace , I simplified the sequence as much as possible and I end up with the the simple fortran programs and R code atached which give the result below. Any explanation about the strange things below and what I should do to avoid them would help. Gilles # QUESTION 1: [EMAIL PROTECTED] guillot]$ R R : Copyright 2005, The R Foundation for Statistical Computing Version 2.2.0 (2005-10-06 r35749) ISBN 3-900051-07-0 >system("R CMD SHLIB ~/tmp/test1.f") g77 -fPIC -g -O2 -c /home/guillot/tmp/test1.f -o /home/guillot/tmp/test1.o gcc -shared -L/usr/local/lib -o /home/guillot/tmp/test1.so /home/guillot/tmp/test1.o -lg2c -lm -lgcc_s > system("R CMD SHLIB ~/tmp/test2.f") g77 -fPIC -g -O2 -c /home/guillot/tmp/test2.f -o /home/guillot/tmp/test2.o gcc -shared -L/usr/local/lib -o /home/guillot/tmp/test2.so /home/guillot/tmp/test2.o -lg2c -lm -lgcc_s > > is.loaded("sub") [1] FALSE > is.loaded("sub_") [1] FALSE > ## OK > dyn.load("~/tmp/test1.so") > is.loaded("sub") [1] FALSE > is.loaded("sub_") [1] TRUE > ## it seems it does not comply with the 'value' section of the help ## of function is.loaded: ## "it needs the ##name you would give to '.C' or '.Fortran' and *not* that remapped ##by 'symbol.C' and 'symbol.For'." ## ## am i missing something ? > q() QUESTION 2: [EMAIL PROTECTED] guillot]$R R : Copyright 2005, The R Foundation for Statistical Computing Version 2.2.0 (2005-10-06 r35749) ISBN 3-900051-07-0 >is.loaded("fstat") [1] FALSE > is.loaded("fstat_") [1] FALSE > dyn.load("~/tmp/test1.so") > is.loaded("fstat") [1] FALSE > is.loaded("fstat_") [1] TRUE ## why ? > dyn.load("~/tmp/test2.so") > .Fortran(name="fstat", + as.integer(999), + as.integer(100), + as.integer(200)) [[1]] [1] 1073913012 [[2]] [1] 0 [[3]] [1] 200 ## pb in memory management ? system("R CMD SHLIB ~/tmp/test1.f") system("R CMD SHLIB ~/tmp/test2.f") is.loaded("sub") is.loaded("sub_") dyn.load("~/tmp/test1.so") is.loaded("sub") is.loaded("sub_") q() R s.loaded("fstat") is.loaded("fstat_") dyn.load("~/tmp/test1.so") is.loaded("fstat") is.loaded("fstat_") dyn.load("~/tmp/test2.so") .Fortran(name="fstat", as.integer(999), as.integer(100), as.integer(200)) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] pb with dyn.load - fortran code now attached
Hi, here are a couple of strange things happening with R.2.2.0 compiled under Mandrake-10.1 At the begining of the story I have segmentation fault using package RandomFields in conjuction with some Fortran code of mine loaded with dyn.load. One of my fortran programs contains a subroutine named fstat Trying to trace , I simplified the sequence as much as possible and I end up with the the simple fortran programs and R code atached which give the result below. Any explanation about the strange things below and what I should do to avoid them would help. Gilles # QUESTION 1: [EMAIL PROTECTED] guillot]$ R R : Copyright 2005, The R Foundation for Statistical Computing Version 2.2.0 (2005-10-06 r35749) ISBN 3-900051-07-0 >system("R CMD SHLIB ~/tmp/test1.f") g77 -fPIC -g -O2 -c /home/guillot/tmp/test1.f -o /home/guillot/tmp/test1.o gcc -shared -L/usr/local/lib -o /home/guillot/tmp/test1.so /home/guillot/tmp/test1.o -lg2c -lm -lgcc_s > system("R CMD SHLIB ~/tmp/test2.f") g77 -fPIC -g -O2 -c /home/guillot/tmp/test2.f -o /home/guillot/tmp/test2.o gcc -shared -L/usr/local/lib -o /home/guillot/tmp/test2.so /home/guillot/tmp/test2.o -lg2c -lm -lgcc_s > > is.loaded("sub") [1] FALSE > is.loaded("sub_") [1] FALSE > ## OK > dyn.load("~/tmp/test1.so") > is.loaded("sub") [1] FALSE > is.loaded("sub_") [1] TRUE > ## it seems it does not comply with the 'value' section of the help ## of function is.loaded: ## "it needs the ##name you would give to '.C' or '.Fortran' and *not* that remapped ##by 'symbol.C' and 'symbol.For'." ## ## am i missing something ? > q() QUESTION 2: [EMAIL PROTECTED] guillot]$R R : Copyright 2005, The R Foundation for Statistical Computing Version 2.2.0 (2005-10-06 r35749) ISBN 3-900051-07-0 >is.loaded("fstat") [1] FALSE > is.loaded("fstat_") [1] FALSE > dyn.load("~/tmp/test1.so") > is.loaded("fstat") [1] FALSE > is.loaded("fstat_") [1] TRUE ## why ? > dyn.load("~/tmp/test2.so") > .Fortran(name="fstat", + as.integer(999), + as.integer(100), + as.integer(200)) [[1]] [1] 1073913012 [[2]] [1] 0 [[3]] [1] 200 ## pb in memory management ? system("R CMD SHLIB ~/tmp/test1.f") system("R CMD SHLIB ~/tmp/test2.f") is.loaded("sub") is.loaded("sub_") dyn.load("~/tmp/test1.so") is.loaded("sub") is.loaded("sub_") q() R s.loaded("fstat") is.loaded("fstat_") dyn.load("~/tmp/test1.so") is.loaded("fstat") is.loaded("fstat_") dyn.load("~/tmp/test2.so") .Fortran(name="fstat", as.integer(999), as.integer(100), as.integer(200)) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] pb with dyn.load - fortran code now attached
> > is.loaded("supsmu_") > > [1] FALSE > > > is.loaded("supsmu") > > [1] TRUE > > That is a Fortran entry point, and it complies with the description > quoted. > > What is.loaded() needs depends on how the symbol would be found > and so it is not much use. OK, thanks. But still > is.loaded("fstat_") [1] FALSE > dyn.load("~/tmp/test1.so") > is.loaded("fstat_") [1] TRUE while test1.so does not contains any reference to fstat. How does anything like fstat happens to be loaded ? Gilles __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] R build under mandriva 10.2
After upgrading from mandrake 10.1 to mandriva 10.2 I can't build shared archive with R 2.2.0 [EMAIL PROTECTED] src]$ R CMD SHLIB main.f sub.f wrapper.c gcc -shared -L/usr/local/lib -o main.so main.o sub.o wrapper.o -lg2c -lm -lgcc_s /usr//bin/ld: cannot find -lg2c collect2: ld returned 1 exit status make: *** [main.so] Erreur 1 I guess the information in http://finzi.psych.upenn.edu/R/Rhelp01/archive/5146.html are not relevant any longer. What is missing ? Gilles __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] R binomial RNG stuck at 1 via Fortran call
Hi, I have some trouble with the result of a fortran function calling the R binomial RNG: The C function rbinom is wrapped as in the file attached. My main fortran program starts as call rndstart() and ends as call rndend() I happen to call the binomial RNG within a loop as b = ggrbinom(1.d0,0.5d0) write(*,*) 'b=',b In certain cases, after a few iterations in the loop, b get stuck at 1 Any hint to explain that would help. Gilles -- ÅÅÅ Gilles Guillot INRA - MIA Paris Currently working from Göteborg Stochastic Centre Eklandagatan 86 - Rum1439 Chalmers University of Technology SE 412-96 Göteborg Sweden Phone +46 31 772 3514 / Fax +46 31772 3508 www.inapg.inra.fr/ens_rech/mathinfo/personnel/guillot/welcome.html ÅÅÅ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] R binomial RNG stuck at 1 via Fortran call
wrapper now attached -- ÅÅÅ Gilles Guillot INRA - MIA Paris Currently working from Göteborg Stochastic Centre Eklandagatan 86 - Rum1439 Chalmers University of Technology SE 412-96 Göteborg Sweden Phone +46 31 772 3514 / Fax +46 31772 3508 www.inapg.inra.fr/ens_rech/mathinfo/personnel/guillot/welcome.html ÅÅÅ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] R binomial RNG stuck at 1 via Fortran call
wrapper now as part as the message, sorry about previous mail #include #include void F77_SUB(rndstart)(void) { GetRNGstate(); } void F77_SUB(rndend)(void) { PutRNGstate(); } double F77_SUB(ggrnorm)(double *mu, double *sigma) { return rnorm(*mu, *sigma); } double F77_SUB(ggrexp)(double *scale) {return rexp(*scale);} double F77_SUB(ggrgam)(double *a, double *scale) {return rgamma(*a, *scale);} double F77_SUB(ggrunif)(double *a, double *b) {return runif(*a, *b);} double F77_SUB(ggrbinom)(double *n, double *p) {return rbinom(*n, *p);} double F77_SUB(ggrpois)(double *lambda) {return rpois(*lambda);} __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] RNG stuck via Fortran call
Having not much success with my previous question I try to reformulate it: I'm simulating a Markow chain in Fortran interfaced with R. Each loop of my Fortran calls various functions of the R RNG through the wrapper given below. In a run of 100 iterations of the Markov kernel, after 20 iterations, the RNG seems like frozen. For example, the first call to the RNG in my loop is: rpostlamb = ggrgam(dble(m),1.d0) write(*,*) 'rpostlamb=',rpostlamb after the 20th iteration, it will return the same value rpostlamb= 1.24634557 for all the following interations. Is there any suggestion of explanation for this strange fact ? Thanks in advance Gilles R Version 2.2.0 compiled under Mandrake 10.1 #include #include /**/ /* random numbers */ /**/ void F77_SUB(rndstart)(void) { GetRNGstate(); } void F77_SUB(rndend)(void) { PutRNGstate(); } double F77_SUB(ggrnorm)(double *mu, double *sigma) { return rnorm(*mu, *sigma); } double F77_SUB(ggrexp)(double *scale) {return rexp(*scale);} double F77_SUB(ggrgam)(double *a, double *scale) {return rgamma(*a, *scale);} double F77_SUB(ggrunif)(double *a, double *b) {return runif(*a, *b);} double F77_SUB(ggrbinom)(double *n, double *p) {return rbinom(*n, *p);} double F77_SUB(ggrpois)(double *lambda) {return rpois(*lambda);} __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] package Geneland / Rgui under windows
Hi, I experienced a problem with the package Geneland under R 2.6.0 with windows XP professional. The commands below should simulate a dataset, then make an MCMC simulation stored in tempdir(). It works with R 2.5.1 (both GUI and command line) It works with the command line of R 2.6.0 but not with the R GUI of 2.6.0: no output file is created in tempdir() and R remains frozen. I reported it as a bug (PR#9964) but did not get any feed back. Thanks in advance for any help. Gilles set.seed(1) data <- simdata(nindiv=200, coord.lim=c(0,1,0,1) , number.nuclei=5 , allele.numbers=rep(10,20), IBD=FALSE, npop=2, give.tess.grid=FALSE) path.mcmc <- paste(tempdir(),"/",sep="") mcmcFmodel(coordinates= t(data$coord.indiv), genotypes=data$genotypes, path.mcmc=path.mcmc, rate.max=10, delta.coord=0, npopmin=1, npopinit=5, npopmax=5, nb.nuclei.max=50, nit=500, thinning=1, freq.model="Dirichlet", varnpop=FALSE, spatial=TRUE) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] package Geneland / Rgui under windows
I forgot to say that I was the package author. I suspected a bug of R as Geneland worked fine for two years and the problem popped up with the release of R 2.6.0 And I can't see any explanation. So, any clue would help. gilles > Gilles GUILLOT wrote: >> Hi, >> I experienced a problem with the package Geneland under R 2.6.0 >> with windows XP professional. >> >> The commands below should simulate a dataset, >> then make an MCMC simulation stored in tempdir(). >> >> It works with R 2.5.1 (both GUI and command line) >> It works with the command line of R 2.6.0 >> but not with the R GUI of 2.6.0: no output file is created in tempdir() >> and R remains frozen. >> I reported it as a bug >> (PR#9964) but did not get any feed back. > > I think the general rule-of-thumb is to contact the package author for > problems with individual packages. Many package authors read this list, > but there are probably some that do not. Sometimes problems with > individual packages are actually bugs in R, but I would say that this is > not usually the case. However, the package author is probably the best > person to make this judgment. > > Sean > _ Gilles GUILLOT INRA MIA Paris - FRANCE Now working from Matematisk Statistik Chalmers University of Technology, S-412 96 Göteborg, SWEDEN Rum: 3079 tel: +46 31 772 5338, Email: [EMAIL PROTECTED] http://www.inapg.inra.fr/ens_rech/mathinfo/personnel/guillot/welcome.html __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel