[Rd] minor typo in docs for 'sort'
Dear all, on the help page for '?sort': 'Method "shell" uses Shellsort ([...] from Sedgewick (1996))' but in the references it is Sedgewick (1986). 1986 seems correct: http://dx.doi.org/10.1016/0196-6774(86)90001-5 Thank you, Enrico -- Enrico Schumann Lucerne, Switzerland http://enricoschumann.net __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Code compilation: Drop certain statements in a function before calling it multiple times?
Hi, I make heavy use of verbose statements in my code, verbose output that can be enabled/disabled via an argument. Here is a dummy example: foo <- function(n=10, verbose=FALSE) { res <- 0; for (k in 1:n) { if (verbose) cat("Iteration ", k, "...\n", sep=""); res <- res + k; if (verbose) cat("Iteration ", k, "...done\n", sep=""); } } res; } Even with verbose=FALSE, one pay an noticeable overhead due to it when calling foo(verbose=FALSE). Thus, before calling it, i'd like to pre-compile this function by dropping the verbose-related statements, e.g. if (verbose) { fooT <- dropVerbose(foo); } such that I basically get: fooT <- function(n=10, verbose=FALSE) { res <- 0; for (k in 1:n) { res <- res + k; } res; } Just to clarify, the immediate use case for this is to compile local functions, e.g. bar <- function(..., verbose=FALSE) { foo <- function(...) { ... }; if (verbose) { foo <- dropVerbose(foo); } foo(..., verbose=verbose); } Instead of me reinventing the wheel does anyone know of tools that makes it easier to drop certain statements in existing functions? RESULTS: > t <- system.time(for (k in 1:1e5) foo()); > tT <- system.time(for (k in 1:1e5) fooT()); > tT/t usersystem elapsed 0.6635514 NaN 0.6605505 I am aware of the 'compiler' package, which is great, but as far as I understand the above speed up when dropping statements still applies; > fooC <- compiler::cmpfun(foo); > fooTC <- compiler::cmpfun(fooT); > tC <- system.time(for (k in 1:1e5) fooC()); > tTC <- system.time(for (k in 1:1e5) fooTC()); > tTC/tC usersystem elapsed 0.6521739 NaN 0.640 Thanks, Henrik PS. The same idea of compilation applies when you make heavy use of assert statements in your development, sanity checks that are there to make sure *your* coding is correct and that basically never fails but you keep in just in case. It would be nice to have an option to have a Just-in-Time (JIT) options for dropping those assert statements, e.g. the user runs through an analysis on some test data and confirms everything works as it should and then launch a two-week jobs where asserts have been dropped. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Using a shared object without installing a library required by the object.
Dear all, I have a C++ code. To create a shared object from this particular code, I had to install a Fortran library on my computer (Mac). The compiled code runs fine on my computer. However, if I try to dyn.load() said shared object on a computer that does not have the Fortran library installed, the object won't load, and instead I get a message below: usr/local/lib/libgfortran.2.dylib Referenced from: /Users/xh/Downloads/foo2.so I wonder if there is any way to compile the original C++ code such that I can include the necessary components of the Fortran library without having to install the library. Thank you in advance. Best, Xiao [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Minimal build of R ...
Hi, I'm making some progress with this, but have hit a sticking point and am looking for a hint. Most of the compilation seems to be going ok, after some liberal use of f2c, but I'm getting compile errors in src/main/connections.c : connections.c:926:43: error: use of undeclared identifier 'SSIZE_MAX' if ((double) size * (double) nitems > SSIZE_MAX) ^ connections.c:937:43: error: use of undeclared identifier 'SSIZE_MAX' if ((double) size * (double) nitems > SSIZE_MAX) ^ connections.c:3354:21: warning: implicit conversion from 'long long' to 'R_xlen_t' (aka 'int') changes value from 4503599627370496 to 0 [-Wconstant-conversion] nnn = (n < 0) ? R_XLEN_T_MAX : n; ~ ^~~~ ../../src/include/Rinternals.h:65:23: note: expanded from macro 'R_XLEN_T_MAX' # define R_XLEN_T_MAX 4503599627370496 ^~~~ connections.c:3662:11: error: duplicate case value '4' case sizeof(long): ^ connections.c:3660:11: note: previous case defined here case sizeof(int): ^ connections.c:3680:11: error: duplicate case value '4' case sizeof(long): ^ connections.c:3678:11: note: previous case defined here case sizeof(int): ^ connections.c:3912:11: error: duplicate case value '4' case sizeof(long): ^ connections.c:3910:11: note: previous case defined here case sizeof(int): ^ connections.c:3956:11: error: duplicate case value '4' case sizeof(long): ^ connections.c:3952:11: note: previous case defined here case sizeof(int): Recall that I'm compiling with emscripten, which uses clang to generate LLVM bitcode, which is then converted to javascript. I'm currently using the existing autotools build scripts, which emscripten tries to twist in to doing something sensible. It's quite possible that it's ending up mis-"./configure"d though. I appreciate this is fairly off-topic, but if anyone has any pointers where to start looking, they would be greatly appreciated :-) Thanks, Jony -- Centre for Cold Matter, The Blackett Laboratory, Imperial College London, London SW7 2BW T: +44 (0)207 5947741 http://www.imperial.ac.uk/people/jony.hudson http://www.imperial.ac.uk/ccm/research/edm http://www.monkeycruncher.org http://j-star.org/ -- On 2 May 2013, at 17:12, Jony Hudson wrote: > Hi, > > I'm trying to cross-compile R to javascript so that it can run in a > web-browser. Take as long as you need to stop laughing. So, as I was saying - > I want to try and get a build of R running in the browser. [If you're not > familiar with it already, you might enjoy looking at emscripten.org. It's a > remarkably capable tool for translating LLVM bitcode to javascript. Check out > some of the demos!] > > I'm trying to start out with the most minimal build of R possible. I can turn > off various options in the configure script, but I'm wondering about the > bundled R packages (base, stats etc). I'm guessing that the native code > portions of these packages are dynamically loaded at runtime, which will > probably need patching. To start off, I'd like to not build these packages if > possible. > > So, is there a way to configure which packages in the library get built or is > it just a case of editing the makefile? And is there a minimal set of them > that would still allow R to run (not be useful - that can come later - just > run)? > > Thanks in advance for any help anyone can provide :-) > > > Jony > > -- > Centre for Cold Matter, The Blackett Laboratory, > Imperial College London, London SW7 2BW > T: +44 (0)207 5947741 > http://www.imperial.ac.uk/people/jony.hudson > http://www.imperial.ac.uk/ccm/research/edm > http://www.monkeycruncher.org > http://j-star.org/ > -- > > __ > 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] Minimal build of R ...
On May 23, 2013, at 23:07 , Jony Hudson wrote: > Hi, > > I'm making some progress with this, but have hit a sticking point and am > looking for a hint. Most of the compilation seems to be going ok, after some > liberal use of f2c, but I'm getting compile errors in src/main/connections.c : > > connections.c:926:43: error: use of undeclared identifier 'SSIZE_MAX' >if ((double) size * (double) nitems > SSIZE_MAX) > ^ > connections.c:937:43: error: use of undeclared identifier 'SSIZE_MAX' >if ((double) size * (double) nitems > SSIZE_MAX) > ^ > connections.c:3354:21: warning: implicit conversion from 'long long' to > 'R_xlen_t' (aka 'int') changes value from 4503599627370496 to 0 > [-Wconstant-conversion] >nnn = (n < 0) ? R_XLEN_T_MAX : n; >~ ^~~~ > ../../src/include/Rinternals.h:65:23: note: expanded from macro 'R_XLEN_T_MAX' > # define R_XLEN_T_MAX 4503599627370496 > ^~~~ > connections.c:3662:11: error: duplicate case value '4' >case sizeof(long): > ^ > connections.c:3660:11: note: previous case defined here >case sizeof(int): > ^ > connections.c:3680:11: error: duplicate case value '4' >case sizeof(long): > ^ > connections.c:3678:11: note: previous case defined here >case sizeof(int): > ^ > connections.c:3912:11: error: duplicate case value '4' >case sizeof(long): > ^ > connections.c:3910:11: note: previous case defined here >case sizeof(int): > ^ > connections.c:3956:11: error: duplicate case value '4' >case sizeof(long): > ^ > connections.c:3952:11: note: previous case defined here >case sizeof(int): > > Recall that I'm compiling with emscripten, which uses clang to generate LLVM > bitcode, which is then converted to javascript. I'm currently using the > existing autotools build scripts, which emscripten tries to twist in to doing > something sensible. It's quite possible that it's ending up > mis-"./configure"d though. > > I appreciate this is fairly off-topic, but if anyone has any pointers where > to start looking, they would be greatly appreciated :-) > Looks like SSIZE_MAX is usually <*/limits.h>: pd$ grep -r SSIZE_MAX /usr/include/ /usr/include/i386/limits.h:#define SSIZE_MAX LONG_MAX/* max value for a ssize_t */ /usr/include/limits.h:#define _POSIX_SSIZE_MAX32767 /usr/include/ppc/limits.h:#define SSIZE_MAX LONG_MAX/* max value for a ssize_t */ If R_xlen_t is int, you need to adjust R_XLEN_T_MAX to INT_MAX or so. The case warnings look like they are bound to happen on systems where int and long have the same size, and should presumably be harmless. > Thanks, > > > Jony > > -- > Centre for Cold Matter, The Blackett Laboratory, > Imperial College London, London SW7 2BW > T: +44 (0)207 5947741 > http://www.imperial.ac.uk/people/jony.hudson > http://www.imperial.ac.uk/ccm/research/edm > http://www.monkeycruncher.org > http://j-star.org/ > -- > > On 2 May 2013, at 17:12, Jony Hudson wrote: > >> Hi, >> >> I'm trying to cross-compile R to javascript so that it can run in a >> web-browser. Take as long as you need to stop laughing. So, as I was saying >> - I want to try and get a build of R running in the browser. [If you're not >> familiar with it already, you might enjoy looking at emscripten.org. It's a >> remarkably capable tool for translating LLVM bitcode to javascript. Check >> out some of the demos!] >> >> I'm trying to start out with the most minimal build of R possible. I can >> turn off various options in the configure script, but I'm wondering about >> the bundled R packages (base, stats etc). I'm guessing that the native code >> portions of these packages are dynamically loaded at runtime, which will >> probably need patching. To start off, I'd like to not build these packages >> if possible. >> >> So, is there a way to configure which packages in the library get built or >> is it just a case of editing the makefile? And is there a minimal set of >> them that would still allow R to run (not be useful - that can come later - >> just run)? >> >> Thanks in advance for any help anyone can provide :-) >> >> >> Jony >> >> -- >> Centre for Cold Matter, The Blackett Laboratory, >> Imperial College London, London SW7 2BW >> T: +44 (0)207 5947741 >> http://www.imperial.ac.uk/people/jony.hudson >> http://www.imperial.ac.uk/ccm/research/edm >> http://www.monkeycruncher.org >> http://j-star.org/ >> -- >> >> __ >> R-devel@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel > > __ > R-devel@r-project.org mailing list > https://stat.eth
Re: [Rd] Using a shared object without installing a library required by the object.
On May 23, 2013, at 4:18 PM, Xiao He wrote: > Dear all, > > I have a C++ code. To create a shared object from this particular code, I > had to install a Fortran library on my computer (Mac). The compiled code > runs fine on my computer. However, if I try to dyn.load() said shared > object on a computer that does not have the Fortran library installed, the > object won't load, and instead I get a message below: > > usr/local/lib/libgfortran.2.dylib > Referenced from: /Users/xh/Downloads/foo2.so > > I wonder if there is any way to compile the original C++ code such that I > can include the necessary components of the Fortran library without having > to install the library. > The Fortran run-time is included with R, so you only need to change the path -- e.g. install_name_tool -change /usr/local/lib/libgfortran.2.dylib /Library/Frameworks/R.framework/Resources/lib/libgfortran.2.dylib /Users/xh/Downloads/foo2.so You can make that permanent on your build machine by running install_name_tool -id /Library/Frameworks/R.framework/Resources/lib/libgfortran.2.dylib /usr/local/lib/libgfortran.2.dylib If you do that, all code compiled against it subsequently will point to the version inside R instead. Cheers, Simon FWIW: There is R-SIG-Mac for Mac-specific questions. > > Thank you in advance. > > Best, > Xiao > > [[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
Re: [Rd] Using a shared object without installing a library required by the object.
Oops, Sorry, did not reply-all: Thanks for the reply Simon, I have a follow-up question: So after I run the first code you suggested on a computer, the shared object will use the Fortran run-time included in R. Does this code change the shared object itself? Meaning if I send this object to yet another computer and run it, will it know to link to the Fortran included in R? Thanks! -Best, Xiao On Thu, May 23, 2013 at 5:06 PM, Xiao He wrote: > Thanks for the reply Simon, > > I have a follow-up question: > > So after I run the first code you suggested on a computer, the shared > object will use the Fortran run-time included in R. Does this code change > the shared object itself? Meaning if I send this object to yet another > computer and run it, will it know to link to the Fortran included in R? > Thanks! > > Best, > Xiao > > > > On Thu, May 23, 2013 at 4:54 PM, Simon Urbanek < > simon.urba...@r-project.org> wrote: > >> On May 23, 2013, at 4:18 PM, Xiao He wrote: >> >> > Dear all, >> > >> > I have a C++ code. To create a shared object from this particular code, >> I >> > had to install a Fortran library on my computer (Mac). The compiled code >> > runs fine on my computer. However, if I try to dyn.load() said shared >> > object on a computer that does not have the Fortran library installed, >> the >> > object won't load, and instead I get a message below: >> > >> > usr/local/lib/libgfortran.2.dylib >> > Referenced from: /Users/xh/Downloads/foo2.so >> > >> > I wonder if there is any way to compile the original C++ code such that >> I >> > can include the necessary components of the Fortran library without >> having >> > to install the library. >> > >> >> The Fortran run-time is included with R, so you only need to change the >> path -- e.g. >> >> install_name_tool -change /usr/local/lib/libgfortran.2.dylib >> /Library/Frameworks/R.framework/Resources/lib/libgfortran.2.dylib >> /Users/xh/Downloads/foo2.so >> >> You can make that permanent on your build machine by running >> >> install_name_tool -id >> /Library/Frameworks/R.framework/Resources/lib/libgfortran.2.dylib >> /usr/local/lib/libgfortran.2.dylib >> >> If you do that, all code compiled against it subsequently will point to >> the version inside R instead. >> >> Cheers, >> Simon >> >> FWIW: There is R-SIG-Mac for Mac-specific questions. >> >> >> > >> > Thank you in advance. >> > >> > Best, >> > Xiao >> > >> > [[alternative HTML version deleted]] >> > >> > __ >> > R-devel@r-project.org mailing list >> > https://stat.ethz.ch/mailman/listinfo/r-devel >> > >> > >> >> > [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel