Re: [Rd] R_alloc problems in R v1.11
On 6 Jul 2005, at 22:06, Uwe Ligges wrote: > Marie-Hélène Ouellette wrote: > >> I'm using the R v1.11 on Macintoch and I seem to have a problem >> with the >> > > There is no version 1.11, and there never was. Current is 2.1.1 > anything > older than 2.x.y is unsupported these days. The latest version of R for OSX available on CRAN (R-2.1.0a.dmg) reports itself as "Version 1.11 (1.11)". This is actually the version of the Macintosh GUI and not the underlying R framework (which is 2.1.0) but it is found where traditional mac users are going to look to find the version information: R -> About R. I think I may have also stumbled across a tiny little bug in .C. I forgot to capitalize Hello: > .C("hello", as.integer(5)) Error in .C("hello", as.integer(5)) : "C" function name not in load table I think it should say '"hello" function name not in load table'. Kjell __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] different results on linux and windows
Hi Klaus, Why not just use R's random number generator? See section 6.3 of Writing R Extensions. It should give you the same sequence of pseudorandom numbers on all platforms. HTH, Kjell On 12 mai 09, at 12:30, Klaus Nordhausen wrote: Dear R experts, we are preparing an R-package to compute the Oja Median which contains some C++ code in which random numbers are needed. To generate the random numbers we use the following Mersenne-Twister implementation: // MersenneTwister.h // Mersenne Twister random number generator -- a C++ class MTRand // Based on code by Makoto Matsumoto, Takuji Nishimura, and Shawn Cokus // Richard J. Wagner v1.0 15 May 2003 rjwag...@writeme.com the random seed for the Mersenne-Twister is provided by our R-function which gives an (random) integer to the C++ function srand() which in turn sets the seed in the code. Using the set.seed in R makes now the results reproducible, but the results differ between windows and linux. Does anyone know what the problem there is? Our suspicion is that the reason is that some libraries are different implemented on linux and windows (XP) compilers. After the program start we set the seed in row 447(vkm.cpp) with srand(int); When the median will be calculated, an intern seed is set with unsigned int seed = rand(); ( in row 100 (vkm.cpp)). This seed will be used to calculate some random subsets and to create a Mersenne Twister object with MTRand rr(seed); (row 156, vkm.cpp). The MTRand Object rr is called with an unsigned Integer, so the important function in the mersenneTwister.h class is in line 87: MTRand( const uint32& oneSeed ); According to that the Random Number Generator uses the methods initialize(oneSeed); and reload(); (inside the method, beginning in line 215) This both methods (line 283 and line 301) are using beside others registers. Could it be that there is a different behavior between Windows and Linux? We do not want to use only srand() since we might need more then the number of pseudo random numbers that algorithm can provide. For those interested and which would like to see the code, a first version of the package, called OjaMedian, is available as source file and windows binary on my homepage: http://www.uta.fi/~klaus.nordhausen/down.html The problem is in the ojaMedian function when the evolutionary algorithm is used. Involved C++-files are mainly vkm.cpp and MersenneTwister.h. We would be very grateful for any advice on how to solve this problem. (below is also a demonstration) Thank you very much in advance, Klaus Results on windows XP: Compiler used: gcc version 4.2.1-sjlj (mingw32-2) library(OjaMedian) set.seed(1) testD <- rmvnorm(20,c(0,0)) summary(testD) V1V2 Min. :-2.2147 Min. :-1.989352 1st Qu.:-0.3844 1st Qu.:-0.399466 Median : 0.3597 Median :-0.054967 Mean : 0.1905 Mean :-0.006472 3rd Qu.: 0.7590 3rd Qu.: 0.655663 Max. : 1.5953 Max. : 1.358680 set.seed(1) ojaMedian(testD) [1] 0.21423705 -0.05799643 sessionInfo() R version 2.9.0 (2009-04-17) i386-pc-mingw32 locale: LC_COLLATE=Finnish_Finland.1252;LC_CTYPE=Finnish_Finland. 1252;LC_MONETARY=Finnish_Finland. 1252;LC_NUMERIC=C;LC_TIME=Finnish_Finland.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] OjaMedian_0.0-14 ICSNP_1.0-3 ICS_1.2-1survey_3.14 [5] mvtnorm_0.9-5 loaded via a namespace (and not attached): [1] tools_2.9.0 Results on Linux Kubuntu 8.10 result of: cat /proc/version: Linux version 2.6.28-11-generic (bui...@palmer) (gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) ) #42-Ubuntu SMP Fri Apr 17 01:57:59 UTC 2009 library(OjaMedian) set.seed(1) testD <- rmvnorm(20,c(0,0)) summary(testD) V1V2 Min. :-2.2147 Min. :-1.989352 1st Qu.:-0.3844 1st Qu.:-0.399466 Median : 0.3597 Median :-0.054967 Mean : 0.1905 Mean :-0.006472 3rd Qu.: 0.7590 3rd Qu.: 0.655663 Max. : 1.5953 Max. : 1.358680 set.seed(1) ojaMedian(testD) (-0.501381, 0.193929)[1] 0.119149071 0.002732100 sessionInfo() R version 2.8.1 (2008-12-22) i486-pc-linux-gnu locale: LC_CTYPE = en_US .UTF -8 ;LC_NUMERIC = C ;LC_TIME = en_US .UTF -8 ;LC_COLLATE = en_US .UTF -8 ;LC_MONETARY = C ;LC_MESSAGES = en_US .UTF -8 ;LC_PAPER = en_US .UTF -8 ;LC_NAME = C ;LC_ADDRESS =C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] OjaMedian_0.0-14 ICSNP_1.0-3 ICS_1.2-1survey_3.14 [5] mvtnorm_0.9-5 -- Klaus Nordhausen Researcher Tampere School of Public Health FIN-33014 University of Tampere phone: +358 3 3551 4153 fax:+358 3 3551 4150 e-mail: klaus.nordhau...@uta.fi __ R-devel@r-project.org mailing list https://stat.ethz.ch/m
Re: [Rd] Matrix with random number
Hi Fabio, Your function myrbeta returns void so assigning the output isn't going to work. Instead you need to call it like a FORTRAN subroutine. Also, I added arguments for the parameters of the beta and moved the fseedi and fseedo calls outside of the loop. This is a pretty basic FORTRAN programming question and there are lots of books that can help you learn FORTRAN. subroutine mat(x,l,c,pa,pb) integer l,c double precision x(l,c), a integer i,j call fseedi() do j = 1, c do i = 1, l call myrbeta(x(i,j),pa,pb) enddo enddo call fseedo() end In R call it like this: storage.mode(x) <- "double" .Fortran("mat", x = x, as.integer(l), as.integer(c), as.double(1), as.double(2)) Cheers, Kjell On 30 juin 09, at 20:02, Fabio Mathias wrote: Thanks Mr. Barry Rowlingson However, the matrix appears to zeros! Notice the code below! Please! Code in fortran subroutine mat(x,l,c,a) integer l,c double precision x(l,c), a integer i,j do j = 1, c do i = 1, l call fseedi() x(i,j) = myrbeta(a,1,2) call fseedo() enddo enddo end In R: dyn.load("func.so") x <- matrix(0,5,6) l <- nrow(x) c <- ncol(x) a <- 0 ..Fortran("mat", x = x, l, c, as.double(a)) Results: $x [,1] [,2] [,3] [,4] [,5] [,6] [1,]000000 [2,]000000 [3,]000000 [4,]000000 [5,]000000 [[2]] [1] 5 [[3]] [1] 6 [[4]] [1] 1 Thanks!!! Fábio Mathias Corrêa UFLA [[elided Yahoo spam]] [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] strange bug? with R CMD check
Hello, I am trying to get a package to pass R CMD check on an iMac running Mac OS X. When the package is named safeBinaryRegression I get the following warning from R CMD check: * checking whether the name space can be loaded with stated dependencies ... WARNING Error in dyn.load(file, DLLpath = DLLpath, ...) : function 'make_lp' not provided by package 'lpSolveAPI' Calls: loadNamespace -> library.dynam -> dyn.load Execution halted A namespace must be able to be loaded with just the base namespace loaded: otherwise if the namespace gets loaded by a saved object, the session will be unable to start. Probably some imports need to be declared in the NAMESPACE file. Here is the contents of the DESCRIPTION: Package: safeBinaryRegression Version: 0.1-2 Date: 2009-07-01 Title: Safe Binary Regression Author: Kjell Konis Maintainer: Kjell Konis Depends: R (>= 2.9.1), lpSolveAPI (>= 5.5.0.14) LinkingTo: lpSolveAPI Description: Overloads the stats::glm function so that a test for the existence of the maximum likelihood estimate is computed as part of the fitting procedure for binary regression models. License: GPL-2 Here is the contents of the NAMESPACE: export(glm) useDynLib(safeBinaryRegression, linprog, reducedLP) The strange thing is that if I change the length of the package name (for example safeBinaryRegression to safeBinaryRegress) the warning goes away and R CMD check completes successfully. Also, regardless of the package name, the package installs and runs as expected. I'm at a loss trying to figure out what's going on. To reproduce: (1) check out the sbr package (which passes R CMD check) svn checkout svn://svn.r-forge.r-project.org/svnroot/sbr/pkg safeBinaryRegression (2) replace sbr with safeBinaryRegression in DESCRIPTION and NAMESPACE (3) run R CMD check Session Info: > sessionInfo() R version 2.9.1 (2009-06-26) i386-apple-darwin8.11.1 locale: fr_CH.UTF-8/en_US.UTF-8/C/C/fr_CH.UTF-8/fr_CH.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base Thanks, Kjell __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] strange bug? with R CMD check
Yes, I managed to work around the problem. You can still reproduce the strange behavior with revision 5 of the package though. svn checkout svn://svn.r-forge.r-project.org/svnroot/sbr/p...@5 safeBinaryRegression Kjell On 22 juil. 09, at 07:31, Paul Johnson wrote: I am guessing you solved this, because I just downloaded your svn files and there's no more "sbr" and the check passes on my system. Right? pj On Tue, Jul 21, 2009 at 8:32 AM, Kjell Konis wrote: Hello, I am trying to get a package to pass R CMD check on an iMac running Mac OS X. When the package is named safeBinaryRegression I get the following warning from R CMD check: * checking whether the name space can be loaded with stated dependencies ... WARNING Error in dyn.load(file, DLLpath = DLLpath, ...) : function 'make_lp' not provided by package 'lpSolveAPI' Calls: loadNamespace -> library.dynam -> dyn.load Execution halted A namespace must be able to be loaded with just the base namespace loaded: otherwise if the namespace gets loaded by a saved object, the session will be unable to start. Probably some imports need to be declared in the NAMESPACE file. Here is the contents of the DESCRIPTION: Package: safeBinaryRegression Version: 0.1-2 Date: 2009-07-01 Title: Safe Binary Regression Author: Kjell Konis Maintainer: Kjell Konis Depends: R (>= 2.9.1), lpSolveAPI (>= 5.5.0.14) LinkingTo: lpSolveAPI Description: Overloads the stats::glm function so that a test for the existence of the maximum likelihood estimate is computed as part of the fitting procedure for binary regression models. License: GPL-2 Here is the contents of the NAMESPACE: export(glm) useDynLib(safeBinaryRegression, linprog, reducedLP) The strange thing is that if I change the length of the package name (for example safeBinaryRegression to safeBinaryRegress) the warning goes away and R CMD check completes successfully. Also, regardless of the package name, the package installs and runs as expected. I'm at a loss trying to figure out what's going on. To reproduce: (1) check out the sbr package (which passes R CMD check) svn checkout svn://svn.r-forge.r-project.org/svnroot/sbr/pkg safeBinaryRegression (2) replace sbr with safeBinaryRegression in DESCRIPTION and NAMESPACE (3) run R CMD check Session Info: sessionInfo() R version 2.9.1 (2009-06-26) i386-apple-darwin8.11.1 locale: fr_CH.UTF-8/en_US.UTF-8/C/C/fr_CH.UTF-8/fr_CH.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base Thanks, Kjell __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Building R package with .c sub-routine files
Create a file named Makevars in the same directory and put the following line in it: OBJECTS=file1.o Then R CMD SHLIB will only compile file1.c. Kjell On Sep 15, 2009, at 8:04 PM, pleyd...@supagro.inra.fr wrote: Lets say I have two source files file1.c and file2.c The latter just contains sub-routines to be used by the first. i.e. in file1.c I have the line #include "file2.c" Let's say "R CMD SHLIB file1.c" runs perfectly and I want to include the code in a package, "R CMD build" also runs fine but R CMD check" gives * checking whether package 'myPackage' can be installed ... ERROR Installation failed. See '/pathto/myPackage.Rcheck/00install.out' for details. basically the compiler is trying to compile file2.c independantly of file1.c which is not what I want and prevents a proper build What's the easiest way to enforce the correct file dependencies when building R packages? cheers David __ 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] interrupting native code
Hello, I have some native code that I would like to allow users to interrupt. However, I would like to do it more gracefully than with R_CheckUserInterrupt(). The solution I came up with is to call the following abort function periodically - if it returns 1 then I clean up and return. int __WINAPI RlpSolveAbortFunction(lprec *lp, void *userhandle) { if(R_interrupts_pending) return(1); return(0); } This seems to work fine on Mac (sans Aqua) and Linux. Is this going to be portable? Also, is there anything else I need to do? For instance set R_interrupts_pending to 0 after I respond to it? Thanks. Kjell __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] interrupting native code
The problem is that my package uses an external pointer to keep track of a structure created by the lp_solve library. If I use R_CheckUserInterrupt in the lp_solve abort function it leaves the structure in a messed-up state after an interrupt occurs. I am not even able to free the memory allocated in the structure. I need to be able to tell the lp_solve functions to interrupt themselves if I am going to support interrupts at all. I took a longer look at errors.c and it seems my solution should work as long as neither HAVE_AQUA nor Win32 are defined. Under the circumstances, I think that's the best I can do. Any suggestions for a UI independent way to check for interrupts would be appreciated. Thanks, Kjell On 15 mai 08, at 16:41, Prof Brian Ripley wrote: How is R_interrupts_pending going to be set? It is set in the interrupt handler for SIGINT, but that is not the only way to indicate an interrupt, and it is not necessarily available to users of GUIs and embedded R. Without servicing the GUIs all interaction will be dead, including sending an interrrupt from menus/buttons/keyboard. See the comment in the code for R_CheckUserInterrupt. On Thu, 15 May 2008, Kjell Konis wrote: Hello, I have some native code that I would like to allow users to interrupt. However, I would like to do it more gracefully than with R_CheckUserInterrupt(). The solution I came up with is to call the following abort function periodically - if it returns 1 then I clean up and return. int __WINAPI RlpSolveAbortFunction(lprec *lp, void *userhandle) { if(R_interrupts_pending) return(1); return(0); } This seems to work fine on Mac (sans Aqua) and Linux. Is this going to be portable? Also, is there anything else I need to do? For instance set R_interrupts_pending to 0 after I respond to it? Thanks. Kjell __ 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
Re: [Rd] interrupting native code
You mean something like this (I return 1 instead of calling onintr())? Will HAVE_AQUA and Win32 be appropriately defined when building my package (I can't see how to check with R CMD config)? int My_CheckUserInterrupt(void) { R_CheckStack(); #if ( defined(HAVE_AQUA) ) /* R_ProcessEvents() from unix/aqua.c*/ if (ptr_R_ProcessEvents) ptr_R_ProcessEvents(); if (R_interrupts_pending) return(1); #elseif ( defined(Win32) ) /* R_ProcessEvents() from gnuwin32/system.c */ while (peekevent()) doevent(); if (UserBreak) { UserBreak = FALSE; return(1); } R_CallBackHook(); if(R_tcldo) R_tcldo(); #else R_PolledEvents(); if (R_interrupts_pending) return(1); #endif return(0); } On 16 mai 08, at 12:43, Prof Brian Ripley wrote: On Fri, 16 May 2008, Kjell Konis wrote: The problem is that my package uses an external pointer to keep track of a structure created by the lp_solve library. If I use R_CheckUserInterrupt in the lp_solve abort function it leaves the structure in a messed-up state after an interrupt occurs. I am not even able to free the memory allocated in the structure. I need to be able to tell the lp_solve functions to interrupt themselves if I am going to support interrupts at all. I took a longer look at errors.c and it seems my solution should work as long as neither HAVE_AQUA nor Win32 are defined. Under the circumstances, I think that's the best I can do. Any suggestions for a UI independent way to check for interrupts would be appreciated. Why not use the same code as R_CheckUserInterrupt but instead of calling onintr, call your own interrupt routine? Thanks, Kjell On 15 mai 08, at 16:41, Prof Brian Ripley wrote: How is R_interrupts_pending going to be set? It is set in the interrupt handler for SIGINT, but that is not the only way to indicate an interrupt, and it is not necessarily available to users of GUIs and embedded R. Without servicing the GUIs all interaction will be dead, including sending an interrrupt from menus/buttons/keyboard. See the comment in the code for R_CheckUserInterrupt. On Thu, 15 May 2008, Kjell Konis wrote: Hello, I have some native code that I would like to allow users to interrupt. However, I would like to do it more gracefully than with R_CheckUserInterrupt(). The solution I came up with is to call the following abort function periodically - if it returns 1 then I clean up and return. int __WINAPI RlpSolveAbortFunction(lprec *lp, void *userhandle) { if(R_interrupts_pending) return(1); return(0); } This seems to work fine on Mac (sans Aqua) and Linux. Is this going to be portable? Also, is there anything else I need to do? For instance set R_interrupts_pending to 0 after I respond to it? Thanks. Kjell __ 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 -- 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] interrupting native code
I would actually prefer a mechanism that simply returns a flag indicating that an interrupt has been requested. Then I would be able to clean up and return on my own - no longjmp required. Also, it would be useful if there was a function similar to R_ProcessEvents that only dealt with keeping the GUI responsive. Cheers, Kjell On 16 mai 08, at 13:54, Luke Tierney wrote: I'm not sure you can make this work as some of the things needed either are or should be private to the core implementation and not available to package code. In any case I would not recommend this approach for two reasons. First, details of what happens in interrupt checking are subject to change and your code would miss those changes unless you track them carefully. More importantly, several things here could generate an error that results in a longjmp and leaves your code in an unstable state. What is needed for this is a mechanism for detecting an interrupt but not doing the longjmp, just returning a flag that a longjmp is needed and enough information to allow it to be made after cleanup code has been run. This has been on my to do list for a while but getting the semantics right is tricky and so it hasn't happened yet. Hopefully it will be in 2.8.0. In the interim you can cobble something together using R_ToplevelExec, interpreting all FALSE return values as user interrupts. Another option, also under consideration but not available yet, is a C mechanism for registering cleanup operations if a longjmp occurs. A quick and dirty version of that could be provided fairly easily but a better version, which would be preferable in the long run, requires a rewrite of the code that implements jumps and cleanup/on.exit actions. This may take a bit longer to implement. Best, luke On Fri, 16 May 2008, Kjell Konis wrote: You mean something like this (I return 1 instead of calling onintr())? Will HAVE_AQUA and Win32 be appropriately defined when building my package (I can't see how to check with R CMD config)? int My_CheckUserInterrupt(void) { R_CheckStack(); #if ( defined(HAVE_AQUA) ) /* R_ProcessEvents() from unix/aqua.c*/ if (ptr_R_ProcessEvents) ptr_R_ProcessEvents(); if (R_interrupts_pending) return(1); #elseif ( defined(Win32) ) /* R_ProcessEvents() from gnuwin32/system.c */ while (peekevent()) doevent(); if (UserBreak) { UserBreak = FALSE; return(1); } R_CallBackHook(); if(R_tcldo) R_tcldo(); #else R_PolledEvents(); if (R_interrupts_pending) return(1); #endif return(0); } On 16 mai 08, at 12:43, Prof Brian Ripley wrote: On Fri, 16 May 2008, Kjell Konis wrote: The problem is that my package uses an external pointer to keep track of a structure created by the lp_solve library. If I use R_CheckUserInterrupt in the lp_solve abort function it leaves the structure in a messed-up state after an interrupt occurs. I am not even able to free the memory allocated in the structure. I need to be able to tell the lp_solve functions to interrupt themselves if I am going to support interrupts at all. I took a longer look at errors.c and it seems my solution should work as long as neither HAVE_AQUA nor Win32 are defined. Under the circumstances, I think that's the best I can do. Any suggestions for a UI independent way to check for interrupts would be appreciated. Why not use the same code as R_CheckUserInterrupt but instead of calling onintr, call your own interrupt routine? Thanks, Kjell On 15 mai 08, at 16:41, Prof Brian Ripley wrote: How is R_interrupts_pending going to be set? It is set in the interrupt handler for SIGINT, but that is not the only way to indicate an interrupt, and it is not necessarily available to users of GUIs and embedded R. Without servicing the GUIs all interaction will be dead, including sending an interrrupt from menus/buttons/keyboard. See the comment in the code for R_CheckUserInterrupt. On Thu, 15 May 2008, Kjell Konis wrote: Hello, I have some native code that I would like to allow users to interrupt. However, I would like to do it more gracefully than with R_CheckUserInterrupt(). The solution I came up with is to call the following abort function periodically - if it returns 1 then I clean up and return. int __WINAPI RlpSolveAbortFunction(lprec *lp, void *userhandle) { if(R_interrupts_pending) return(1); return(0); } This seems to work fine on Mac (sans Aqua) and Linux. Is this going to be portable? Also, is there anything else I need to do? For instance set R_interrupts_pending to 0 after I respond to it? Thanks. Kjell __ 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,
Re: [Rd] interrupting native code
I have a structure from a library that I am using an external pointer to keep track of. The methods in this library (lp_solve) have the facility to call a function periodically and I would like to use R_ProcessEvents. The problem is that if an interrupt is requested then R returns to the command prompt without completing the library method. This leaves the structure in a messed-up state so that I can't even successfully delete it, potentially leaking a lot of memory. So what I am trying to do is find a way to see if an event has occurred (in this case an interrupt) so I can respond to it before onintr() gets called. Kjell On 20 mai 08, at 19:22, Simon Urbanek wrote: On May 20, 2008, at 10:58 AM, Kjell Konis wrote: I would actually prefer a mechanism that simply returns a flag indicating that an interrupt has been requested. Then I would be able to clean up and return on my own - no longjmp required. Also, it would be useful if there was a function similar to R_ProcessEvents that only dealt with keeping the GUI responsive. I don't understand what you mean by the last sentence - that is exactly what R_ProcessEvents is for - or am I missing something? Cheers, Simon Cheers, Kjell On 16 mai 08, at 13:54, Luke Tierney wrote: I'm not sure you can make this work as some of the things needed either are or should be private to the core implementation and not available to package code. In any case I would not recommend this approach for two reasons. First, details of what happens in interrupt checking are subject to change and your code would miss those changes unless you track them carefully. More importantly, several things here could generate an error that results in a longjmp and leaves your code in an unstable state. What is needed for this is a mechanism for detecting an interrupt but not doing the longjmp, just returning a flag that a longjmp is needed and enough information to allow it to be made after cleanup code has been run. This has been on my to do list for a while but getting the semantics right is tricky and so it hasn't happened yet. Hopefully it will be in 2.8.0. In the interim you can cobble something together using R_ToplevelExec, interpreting all FALSE return values as user interrupts. Another option, also under consideration but not available yet, is a C mechanism for registering cleanup operations if a longjmp occurs. A quick and dirty version of that could be provided fairly easily but a better version, which would be preferable in the long run, requires a rewrite of the code that implements jumps and cleanup/on.exit actions. This may take a bit longer to implement. Best, luke On Fri, 16 May 2008, Kjell Konis wrote: You mean something like this (I return 1 instead of calling onintr())? Will HAVE_AQUA and Win32 be appropriately defined when building my package (I can't see how to check with R CMD config)? int My_CheckUserInterrupt(void) { R_CheckStack(); #if ( defined(HAVE_AQUA) ) /* R_ProcessEvents() from unix/aqua.c*/ if (ptr_R_ProcessEvents) ptr_R_ProcessEvents(); if (R_interrupts_pending) return(1); #elseif ( defined(Win32) ) /* R_ProcessEvents() from gnuwin32/system.c */ while (peekevent()) doevent(); if (UserBreak) { UserBreak = FALSE; return(1); } R_CallBackHook(); if(R_tcldo) R_tcldo(); #else R_PolledEvents(); if (R_interrupts_pending) return(1); #endif return(0); } On 16 mai 08, at 12:43, Prof Brian Ripley wrote: On Fri, 16 May 2008, Kjell Konis wrote: The problem is that my package uses an external pointer to keep track of a structure created by the lp_solve library. If I use R_CheckUserInterrupt in the lp_solve abort function it leaves the structure in a messed-up state after an interrupt occurs. I am not even able to free the memory allocated in the structure. I need to be able to tell the lp_solve functions to interrupt themselves if I am going to support interrupts at all. I took a longer look at errors.c and it seems my solution should work as long as neither HAVE_AQUA nor Win32 are defined. Under the circumstances, I think that's the best I can do. Any suggestions for a UI independent way to check for interrupts would be appreciated. Why not use the same code as R_CheckUserInterrupt but instead of calling onintr, call your own interrupt routine? Thanks, Kjell On 15 mai 08, at 16:41, Prof Brian Ripley wrote: How is R_interrupts_pending going to be set? It is set in the interrupt handler for SIGINT, but that is not the only way to indicate an interrupt, and it is not necessarily available to users of GUIs and embedded R. Without servicing the GUIs all interaction will be dead, including sending an interrrupt from menus/buttons/keyboard. See the comment in the code for R_CheckUserInterrupt. On Thu, 15 May 2008, Kjell Konis wrote: Hello, I have some native code that I would like
[Rd] how to install header files in package
Is there a way to get R CMD INSTALL (and friends) to copy the header files from a source package's src directory to the include directory? Thanks. Kjell __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] how to install header files in package
Here's what I'm doing: I define some C functions in pkgA and register them with R_RegisterCCallable and I want to use them in pkgB. When building pkgB, R CMD INSTALL expects to find the header files for the registered C functions in pkgA*/include (where the * denotes the installed version of pkgA). AFAICT there is no mechanism to put the header files from pkgA into pkgA*/include. Putting the header files in pkgA/inst/include solves the problem but it seems like there should be a better way to do this. Kjell On 13 juin 08, at 16:54, Bill Dunlap wrote: On Fri, 13 Jun 2008, Dirk Eddelbuettel wrote: On 13 June 2008 at 14:28, Kjell Konis wrote: | Is there a way to get R CMD INSTALL (and friends) to copy the header | files from a source package's src directory to the include directory? Only if you (ab-)use the 'make all' target in src/Makefile to copy them, as a recent thread on r-devel showed. Some of us suggested that a 'make install' target would be a nice thing to have. Which 'include' directory do you mean? $RHOME/include or /include? You could put a copy of the *.h files into inst/include to get them into /include. Putting them into $RHOME/include isn't always desirable or possible (permission problems). If you install *.h files then you are probably also distributing *.so, *.dll, and *.lib (on Windows) files and they should go into a parallel directory. Where should they go? Bill Dunlap Insightful Corporation bill at insightful dot com "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] R, Macports and C++ streams
I found this in Writing R Extensions: "Using C++ iostreams, as in this example, is best avoided. There is no guarantee that the output will appear in the R console, and indeed it will not on the R for Windows console. Use R code or the C entry points (see Printing) for all I/O if at all possible." That is, use Rprintf() instead. The fact that your code works with one version of gcc and not another can probably be chalked up to coincidence. Kjell On Jul 30, 2008, at 3:45 PM, Ernest Turro wrote: Dear all, R on Macports relies on GCC 4.3 to build packages. I find that packages with shared objects that use C++ streams crash R if they're compiled using Macports' gcc43, but work fine if compiled in exactly the same way using Apple-supplied GCC 4.2. Has anyone here had the same issue/know what is causing this problem? Thanks, Ernest __ 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
Re: [Rd] R, Macports and C++ streams
Ernest, Is it possible to provide a reproducible example of your crash? Kjell On Jul 30, 2008, at 6:32 PM, Ernest Turro wrote: On 30 Jul 2008, at 15:46, Simon Urbanek wrote: On Jul 30, 2008, at 9:45 , Ernest Turro wrote: Dear all, R on Macports relies on GCC 4.3 to build packages. I find that packages with shared objects that use C++ streams crash R if they're compiled using Macports' gcc43, but work fine if compiled in exactly the same way using Apple-supplied GCC 4.2. Has anyone here had the same issue/know what is causing this problem? Using compilers from MacPorts and similar suites (Darwin ports, Fink etc.) is strongly discouraged (and outright not supported by the CRAN binary) since they have been known to be badly broken in the past and when whenever tested so far they were incomplete and incompatible. You have to re-compile R yourself with those tools (and you're entirely on your own) if you really want to use them. CRAN binaries work only with Apple's gcc branches, if you want to use anything else, you have to follow the unix R instructions and compile everything from sources. Dear Kjell, As you can see above, your R port on Macports appears to be broken and has a reputation of having been broken for a while. I for one have experienced odd problems as described above. To avoid further issues with unsuspecting Macports users, perhaps it would be good to pull the port from the repository until a decent level of reliability can be provided ? Cheers, Ernest Cheers, Simon __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] string comparison
Hi, I have a package where I do things like this a lot: if(strncmp(CHAR(asChar(Scategory)), "chance", 6) == 0) category = h_category_chance; else if(strncmp(CHAR(asChar(Scategory)), "utility", 7) == 0) category = h_category_utility; else if(strncmp(CHAR(asChar(Scategory)), "decision", 8) == 0) category = h_category_decision; else if(strncmp(CHAR(asChar(Scategory)), "instance", 8) == 0) category = h_category_instance; else category = h_category_error; I would like to replace the strncmps with pointer comparisons so I set up some global variables in the R_init_myDLL function like this: charChance = install("chance") but I can't seem to get the comparison to work. I want to do something like if(CHAR(asChar(Scategory)) == charChance) category = h_category_chance; but category always ends up being h_category_error. Any pointers would be appreciated. Thanks, Kjell __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] the %ProgramFiles% variable
Hello, I want to use the %ProgramFiles% variable in a Sys.setenv (R 2.7.2, Windows) but it always seems to get handled literally. For instance, in cmd.exe I get what I want C:\Documents and Settings\user>echo %ProgramFiles% C:\Program Files but in R > system("echo %ProgramFiles%") %ProgramFiles% nope. Is there a way to use %ProgramFIles% or get the corresponding path? Thanks, Kjell __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] calculating means per group
Hi Luc, First of all, questions like this should really be asked on the R-help mailing list. The tapply function does what you want: > year [1] 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 Levels: 1 2 > area [1] a a a a a b b b b a a a a b b b b b Levels: a b > value [1] 20 25 28 31 23 25 28 23 19 25 23 24 26 27 28 20 25 28 Note that both year and area are factors. Get the mean for each area: > tapply(value, area, mean) ab 25.0 24.8 If you make the second argument a list then you can subset on both factor columns: > tapply(value, list(year, area), mean) a b 1 25.4 23.75 2 24.5 25.60 Kjell On 4 sept. 08, at 09:06, RFTW wrote: Hi all I have a very basic question, yet i have not found how to do it. Suppose my dataset looks like this: YearAreavalue 1 a 20 1 a 25 1 a 28 1 a 31 1 a 23 1 b 25 1 b 28 1 b 23 1 b 19 2 a 25 2 a 23 2 a 24 2 a 26 2 b 27 2 b 28 2 b 20 2 b 25 2 b 28 Now, i want to calculate a MEAN per year per area. How do i do that? With mean(value) i calculate the mean of all values of course. I just need to know how to group year and area correctly. I assume that i can use this grouping in other calculations too, right? Cheers, Luc -- View this message in context: http://www.nabble.com/calculating-means-per-group-tp19271479p19271479.html Sent from the R devel mailing list archive at Nabble.com. __ 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
Re: [Rd] Label justification (axis) (PR#13307)
If you want to change the orientation of the axis labels you use las. If you want to change the horizontal justification of the axis labels you use hadj. If you want to change the orientation of the axis labels and the horizontal justification of the axis labels then you use las and hadj at the same time. On 20 nov. 08, at 14:45, [EMAIL PROTECTED] wrote: Full_Name: Martin Karl-Friedrich Bader Version: 2.8.0 OS: 10.5.3 Submission from: (NULL) (131.152.1.1) Hi there, when using las=1 on the y-axis the labels keep their centered justification, e.g. if you plot a graph using the axis command: axis(side=2, at=c(0,50, 100, 125), lab=c("0","50","100", " "), las=1), then the 0 and the 50 are centered in relation to the 100! One can work around that problem by inserting blank spaces in front of the lower numbers (e.g.: " 0") but that's not an appropriate solution! Is there a way that can be fixed? Thanks in advance! Martin __ 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
Re: [Rd] Generate random numbers in Fortran
Take a look at section 6.6 in Writing R Extensions. It describes how to call C functions from FORTRAN. Basically it just boils down to this, in a C file define the functions void F77_SUB(fseedi)(void) { int x = 100; seed_in(&x); } void F77_SUB(fseedo)(void) { int x = 100; seed_out(&x); } void F77_SUB(myrunif)(double* px) { *px = unif_rand(); } Then you could write a FORTRAN subroutine like subroutine blah() implicit double precision (a-h,o-z) call fseedi() call myrunif(RND) call fseedo() end The fseed* subroutines only need to be called once, fseedi at the beginning of your FORTRAN code and fseedo at the end. HTH, Kjell On 13 févr. 09, at 17:32, Fabio Mathias wrote: Hi!!! It would like to know if it exists a form to use the functions to generate variates in FORTRAN with the same easiness I use that them in C? Or not? If yes. They would have some example? I would like to use the functions rbeta, rlnorm and others! Sorry my english..rsrsrs Thanks!!! Fábio Mathias CorrêaUniversity Federal of the Lavras - Brazil Veja quais são os assuntos do momento no Yahoo! +Buscados [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Generate random numbers in Fortran
Sorry, my example was just to give you a rough idea of how to do this. Here is an example that works. myrandom.c: #include #include void F77_SUB(fseedi)(void) { GetRNGstate(); } void F77_SUB(fseedo)(void) { PutRNGstate(); } void F77_SUB(myrbeta)(double* px, double* pa, double* pb) { *px = rbeta(*pa, *pb); } and example.f subroutine example(x, a, b) implicit double precision (a-h,o-z) call fseedi() call myrbeta(x, a, b) call fseedo() end Note: it is important that there are 6 spaces at the beginning of each line. Also, don't do this: void F77_SUB(myrbeta)(double* px) { GetRNGstate(); *px = rbeta(1.00,3.00); PutRNGstate(); } It spends more time seeding the random number generator than generating random numbers. Regards, Kjell On Feb 14, 2009, at 11:09 AM, Fabio Mathias wrote: > As I am wanting to generate a beta, then I created a function in C > to generate a beta, but the problem appears when I go to compile > > My function in C is > > #include > #include > #include > > void F77_SUB(myrbeta)(double* px) > { > GetRNGstate(); > *px = rbeta(1.00,3.00); > PutRNGstate(); > } > > My function in Fortran is > > subroutine blah(a) > double precision (a) > call myrbeta(RND) > end > > The error > > fmc...@fmcron-desktop:~/teste$ R CMD SHLIB mat.c blah.f > gcc -std=gnu99 -I/usr/share/R/include -fpic -g -O2 -c mat.c - > o mat.o > gfortran -fpic -g -O2 -c blah.f -o blah.o > blah.f:1.1: > > subroutine blah(a) > 1 > Erro: Non-numeric character in statement label at (1) > blah.f:1.1: > > subroutine blah(a) > 1 > Erro: Unclassifiable statement at (1) > blah.f:2.1: > > double precision (a) > 1 > Erro: Non-numeric character in statement label at (1) > blah.f:2.1: > > double precision (a) > 1 > Erro: Unclassifiable statement at (1) > blah.f:4.1: > > end > 1 > Erro: Non-numeric character in statement label at (1) > blah.f:4.1: > > end > 1 > Erro: Unclassifiable statement at (1) > make: ** [blah.o] Erro 1 > > > Fábio Mathias Corrêa >UFLA > > > --- Em sex, 13/2/09, Kjell Konis escreveu: > De: Kjell Konis > Assunto: Re: [Rd] Generate random numbers in Fortran > Para: "fabio.u...@yahoo.com.br" > Cc: "r-devel@r-project.org" > Data: Sexta-feira, 13 de Fevereiro de 2009, 16:49 > > Take a look at section 6.6 in Writing R Extensions. It describes > how to call C > functions from FORTRAN. > > Basically it just boils down to this, in a C file define > the functions > > void F77_SUB(fseedi)(void) > { > int x = 100; > seed_in(&x); > } > > > void F77_SUB(fseedo)(void) > { > int x = 100; > seed_out(&x); > } > > > void F77_SUB(myrunif)(double* px) > { > *px = unif_rand(); > } > > > Then you could write a FORTRAN subroutine like > > subroutine blah() > implicit double precision (a-h,o-z) > call fseedi() > call myrunif(RND) > call fseedo() > end > > The fseed* subroutines only need to be called once, fseedi at the > beginning of > your FORTRAN code and fseedo at the end. > > HTH, > Kjell > > > On 13 févr. 09, at 17:32, Fabio Mathias wrote: > > > Hi!!! > > It would like to know if it exists a form to use the functions to > > generate variates in FORTRAN with the same easiness I use that > them in > > C? Or not? > > If yes. They > > would have some example? I would like to use the functions > rbeta, rlnorm and others! > > > > > > Sorry my english..rsrsrs > > > > Thanks!!! > > > > > > Fábio Mathias CorrêaUniversity Federal of the > Lavras - > Brazil > > > > > > > > Veja quais são os assuntos do momento no Yahoo! +Buscados > > > > [[alternative HTML version deleted]] > > > > > > > Veja quais são os assuntos do momento no Yahoo! + Buscados: Top 10 > - Celebridades - Música - Esportes [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] demo enhancement
Hello, I have a package for working with Bayesian networks (RHugin - on R- Forge for those interested). It contains a function RHExample that does the same thing as the demo function in the utils package except that it does not display any output in the R console. I use it to build simple networks in the examples section of my .Rd documentation files. Anyway, I thought it would be useful if this functionality was also part of the demo function. The attached diff adds an echo argument to demo which, when set to FALSE, makes demo behave the same as my RHExample function. Please feel free to use it if you think it would be helpful. Kjell __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] demo enhancement
I put the diff here http://smat.epfl.ch/~konis/grabbag/demo.diff Kjell On 16 févr. 09, at 12:35, Duncan Murdoch wrote: Kjell Konis wrote: Hello, I have a package for working with Bayesian networks (RHugin - on R- Forge for those interested). It contains a function RHExample that does the same thing as the demo function in the utils package except that it does not display any output in the R console. I use it to build simple networks in the examples section of my .Rd documentation files. Anyway, I thought it would be useful if this functionality was also part of the demo function. The attached diff adds an echo argument to demo which, when set to FALSE, makes demo behave the same as my RHExample function. Please feel free to use it if you think it would be helpful. Your attachment got lost, but by coincidence, I was wanting an echo=FALSE argument to demo a couple of days ago. I didn't add it yet, because - I'd like consistency with example(), which suggests putting echo ahead of verbose - I'd rather not add a parameter in the middle of the list, just in case someone has used positional args - example() has other args not in demo(), i.e. local, setRNG, ask, prompt.prefix. Should some or all of those be added at the same time? Since the first two items above are contradictory, I decided this needed thinking about, but I haven't taken the time to do that yet. Duncan Murdoch __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] copy an external pointer on assignment
Is there a mechanism in R for copying the business end of an external pointer on assignment? For instance, if x is an external pointer and I enter > y <- x I would like to make a copy of the structure that x refers to and assign its address to y. Thanks, Kjell __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel