[Rd] Problems with MinGW and boost on Windows
Hi, I am not sure how widespread this problem is, but definitely occurs for me on 64 bit Win 7 with a 64 bit R. I think I have isolated the issue (to a certain extent) in the attached Test.cpp file. Basically, I think linking with boost serialization is causing the plugin to fail. If I compile Test.cpp with line 43 (Dummy* Read() ...) commented out, I get the expected output in R: > dyn.load("../MinGW/Debug64/Tester.dll",DLLpath="C:/Sys/boost/MinGW64/boost_1_50_0/lib") Hello World. > .Call("add",c(1,3)) [1] 4 > is.loaded("add") [1] TRUE However, if line 43 is uncommented, the output changes to > dyn.load("../MinGW/Debug64/Tester.dll",DLLpath="C:/Sys/boost/MinGW64/boost_1_50_0/lib") Hello World. > .Call("add",c(1,3)) Error in .Call("add", c(1, 3)) : C symbol name "add" not in load table > is.loaded("add") [1] FALSE I am not sure what exactly is going wrong. This happens both if I link to boost serialization statically or dynamically. This is on R version R-2.15.1, and both boost serialization libraries and the plugin are built with the gcc (4.6.3 20111208 prerelease) and make.exe provided by RTools (Collection 2.16.0.1923) using the -m64 flag. Build command was g++ -c "Test.cpp" -g -std=gnu++0x -m64 -O1 -DDEBUG -o obj/Debug64/Tester/Trunk_Test.o -I. -I/R/R-2.15.1/include -I/R/R-2.15.1/library/Rcpp/include -I/Sys/boost/boost_1_50_0 g++ -shared -fPIC -o Debug64/Tester.dll @"MinGW\Tester.txt" -L. -L/R/R-2.15.1/library/Rcpp/lib/x64 -L/R/R-2.15.1/bin/x64 -L/Sys/boost/MinGW64/boost_1_50_0/lib -LDebug64 -lRcpp -lR -lboost_serialization-mgw46-mt-d-1_50 -lboost_system-mgw46-mt-d-1_50 -Wl,--out-implib="Debug64/libTester.a" -m64 And for boost: b2.exe --prefix=c:\Sys\boost\MinGW64\boost_1_50_0 toolset=gcc address-model=64 link=static,shared -s BZIP2_SOURCE=C:\Sys\bzip2-1.0.6 -s ZLIB_SOURCE=C:\Sys\zlib-1.2.7 install Also note that this works fine on linux (Ubuntu). I have been struggling to get past this for several weeks now... any help would be greatly appreciated. Thanks, Florian __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Problems with MinGW and boost on Windows
Sorry, didn't realize text attachments get stripped as well... here is a link: http://pastebin.com/T3XhsjDY, and for the archives the actual text #define WIN32_LEAN_AND_MEAN #define NOMINMAX 1 #define _WIN32_WINNT 0x0601 #define NTDDI_VERSION 0x0601 #define _MSC_VER_WINNT _MSC_VER_WINNT_WIN7 #include #include #include struct World { World() { Rprintf("Hello World.\n"); } ~World() { Rprintf("Goodbye World.\n"); } }; World myWorld; extern "C" { SEXP add(SEXP symName); } SEXP add( SEXP x ) { Rcpp::NumericVector xx(x); return Rcpp::wrap( std::accumulate( xx.begin(), xx.end(), 0.0)); } #define NVP(x) boost::serialization::make_nvp(#x,x) class Dummy { public: int a; Dummy() { } template void serialize(Archive& ar, const unsigned int) { ar & NVP(a); } }; class DummyReader { std::ifstream myifstream; boost::archive::binary_iarchive ar; public: DummyReader(std::string const& filename) : myifstream(filename,std::ios_base::in | std::ios_base::binary), ar(myifstream) { } Dummy* Read() { Dummy* item; try {ar & NVP(item); } catch (boost::archive::archive_exception const&) { item=0; } return item; } }; __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Puzzling behavior while testing
I'm testing a new release of survival, executing the following piece of code: for (testpkg in survdep) { z <- testInstalledPackage(testpkg, outDir="tests") cat(testpkg, c("Ok", "Failed")[z+1], "\n", file="progress", append=T) } The vector survdep contains the names of all 156 packages listed as reverse depends on the CRAN page for survival. All works well except for the packages coin and compareGroups. If we make the survdep list contain only those 2 then the last line above "cat..." fails with "testpkg not found". Running ls() at that point shows a set of variables I didn't define, and no evidence of any of "testpkg", "survdep", or anything else I'd defined. My prompt has been changed to "R>" as well. Any idea what is happening? Terry Therneau Here is the text just before starting the loop > sessionInfo() R version 2.15.2 (2012-10-26) Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=C [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] tools stats graphics grDevices utils datasets methods [8] base __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] R CMD check fails when run in a directory with parentheses in the pathname
For what it's worth: running R CMD check on a package when the outdir has parentheses in the pathname fails with the following error: * checking PDF version of manual ...sh: Syntax error: "(" unexpected WARNING LaTeX errors when creating PDF version. This typically indicates Rd problems. * checking PDF version of manual without hyperrefs or index ...sh: Syntax error: "(" unexpected ERROR Re-running with no redirection of stdout/stderr. The workaround is as simple as using -o to redirect the output to a sane path. This could be just a case of "don't do this", but I wanted to save some future problem-Googler 10 minutes of digging around in the guts of .tools:::check_packages() to find out what was going on ... I don't know whether this is technically a bug or not. Presumably something could be tweaked in check_pkg_manual() within src/library/tools/R/check.R to protect parentheses in the shell argument string ... Ben Bolker __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] R CMD check: better diagnosis for non-ASCII characters
[Env: R 2.15.1, Win Xp] Suggestion: Could the R script that checks for non-ASCII characters in R CMD check not give either: (a) a pointer to tools:::showNonASCIIfile, as in, try running tools:::showNonASCIIfile("Battig.Rd") or, (b) perhaps more useful, the result of tools:::showNonASCIIfile(file.Rd) on the offending file(s). I'm frequently bitten by this in preparing .Rd files when I copy/paste references to the .Rd from a .pdf or web link. But it is nearly impossible to see these variant characters in my .Rd files with any editor. This recent example was solved by > tools:::showNonASCIIfile("Battig.Rd") 47: \emph{Journal of Experimental Psychology}, 80 (1969), pp. 1<96>46 but I had to find this function again via ??ascii because it is not exported. -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. & Chair, Quantitative Methods York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] bug with mapply() on an S4 object
Hi, Here is a patch for this (against current R-devel). The "caching" of the .Primitive for 'length' is taken from seq_along() C code (in R-devel/src/main/seq.c). hpages@thinkpad:~/svn/R$ svn diff R-devel Index: R-devel/src/main/mapply.c === --- R-devel/src/main/mapply.c (revision 61172) +++ R-devel/src/main/mapply.c (working copy) @@ -32,14 +32,39 @@ int i, j, m, named, zero = 0; R_xlen_t *lengths, *counters, longest = 0; SEXP vnames, fcall = R_NilValue, mindex, nindex, tmp1, tmp2, ans; +static SEXP length_op = NULL; +/* Store the .Primitive for 'length' for DispatchOrEval to use. */ +if (length_op == NULL) { + SEXP R_lengthSymbol = install("length"); + length_op = eval(R_lengthSymbol, R_BaseEnv); + if (TYPEOF(length_op) != BUILTINSXP) { + length_op = NULL; + error("'length' is not a BUILTIN"); + } + R_PreserveObject(length_op); +} + m = length(varyingArgs); vnames = PROTECT(getAttrib(varyingArgs, R_NamesSymbol)); named = vnames != R_NilValue; lengths = (R_xlen_t *) R_alloc(m, sizeof(R_xlen_t)); for(i = 0; i < m; i++){ - lengths[i] = xlength(VECTOR_ELT(varyingArgs, i)); + int dispatch_ok = 0; + tmp1 = VECTOR_ELT(varyingArgs, i); + if (isObject(tmp1)) { + /* Looks like DispatchOrEval() needs a pairlist. We reproduce what + pairlist(tmp1) would do i.e. tmp2 <- as.pairlist(list(tmp1)). + Is there a more direct way to go from tmp1 to tmp2? */ + PROTECT(tmp2 = allocVector(VECSXP, 1)); + SET_VECTOR_ELT(tmp2, 0, tmp1); + PROTECT(tmp2 = coerceVector(tmp2, LISTSXP)); + dispatch_ok = DispatchOrEval(call, length_op, "length", +tmp2, rho, &ans, 0, 1); + UNPROTECT(2); + } + lengths[i] = dispatch_ok ? asInteger(ans) : xlength(tmp1); if(lengths[i] == 0) zero++; if (lengths[i] > longest) longest = lengths[i]; } Hopefully the bug can be fixed. Thanks! H. On 11/14/2012 09:42 PM, Hervé Pagès wrote: Hi, Starting with ordinary vectors, so we know what to expect: > mapply(function(x, y) {x * y}, 101:106, rep(1:3, 2)) [1] 101 204 309 104 210 318 > mapply(function(x, y) {x * y}, 101:106, 1:3) [1] 101 204 309 104 210 318 Now with an S4 object: setClass("A", representation(aa="integer")) a <- new("A", aa=101:106) > length(a) [1] 1 Implementing length(): setMethod("length", "A", function(x) length(x@aa)) Testing length(): > length(a) # sanity check [1] 6 No [[ yet for those objects so the following error is expected: > mapply(function(x, y) {x * y}, a, rep(1:3, 2)) Error in dots[[1L]][[1L]] : this S4 class is not subsettable Implementing [[: setMethod("[[", "A", function(x, i, j, ...) x@aa[[i]]) Testing [[: > a[[1]] [1] 101 > a[[5]] [1] 105 Trying mapply again: > mapply(function(x, y) {x * y}, a, rep(1:3, 2)) [1] 101 202 303 101 202 303 Wrong. It looks like internally a[[1]] is always used instead of a[[i]]. The real problem it seems is that 'a' is treated as if it was of length 1: > mapply(function(x, y) {x * y}, a, 1:3) [1] 101 202 303 > mapply(function(x, y) {x * y}, a, 5) [1] 505 In other words, internal dispatch works for [[ but not for length(). Thanks, H. -- Hervé Pagès Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M1-B514 P.O. Box 19024 Seattle, WA 98109-1024 E-mail: hpa...@fhcrc.org Phone: (206) 667-5791 Fax:(206) 667-1319 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] bug with mapply() on an S4 object
Some formatting issues when copy/pasting the patch in the body of the email so I've attached the diff file. Cheers, H. On 11/27/2012 04:56 PM, Hervé Pagès wrote: Hi, Here is a patch for this (against current R-devel). The "caching" of the .Primitive for 'length' is taken from seq_along() C code (in R-devel/src/main/seq.c). hpages@thinkpad:~/svn/R$ svn diff R-devel Index: R-devel/src/main/mapply.c === --- R-devel/src/main/mapply.c(revision 61172) +++ R-devel/src/main/mapply.c(working copy) @@ -32,14 +32,39 @@ int i, j, m, named, zero = 0; R_xlen_t *lengths, *counters, longest = 0; SEXP vnames, fcall = R_NilValue, mindex, nindex, tmp1, tmp2, ans; +static SEXP length_op = NULL; +/* Store the .Primitive for 'length' for DispatchOrEval to use. */ +if (length_op == NULL) { +SEXP R_lengthSymbol = install("length"); +length_op = eval(R_lengthSymbol, R_BaseEnv); +if (TYPEOF(length_op) != BUILTINSXP) { +length_op = NULL; +error("'length' is not a BUILTIN"); +} +R_PreserveObject(length_op); +} + m = length(varyingArgs); vnames = PROTECT(getAttrib(varyingArgs, R_NamesSymbol)); named = vnames != R_NilValue; lengths = (R_xlen_t *) R_alloc(m, sizeof(R_xlen_t)); for(i = 0; i < m; i++){ -lengths[i] = xlength(VECTOR_ELT(varyingArgs, i)); +int dispatch_ok = 0; +tmp1 = VECTOR_ELT(varyingArgs, i); +if (isObject(tmp1)) { +/* Looks like DispatchOrEval() needs a pairlist. We reproduce what + pairlist(tmp1) would do i.e. tmp2 <- as.pairlist(list(tmp1)). + Is there a more direct way to go from tmp1 to tmp2? */ +PROTECT(tmp2 = allocVector(VECSXP, 1)); +SET_VECTOR_ELT(tmp2, 0, tmp1); +PROTECT(tmp2 = coerceVector(tmp2, LISTSXP)); +dispatch_ok = DispatchOrEval(call, length_op, "length", + tmp2, rho, &ans, 0, 1); +UNPROTECT(2); +} +lengths[i] = dispatch_ok ? asInteger(ans) : xlength(tmp1); if(lengths[i] == 0) zero++; if (lengths[i] > longest) longest = lengths[i]; } Hopefully the bug can be fixed. Thanks! H. On 11/14/2012 09:42 PM, Hervé Pagès wrote: Hi, Starting with ordinary vectors, so we know what to expect: > mapply(function(x, y) {x * y}, 101:106, rep(1:3, 2)) [1] 101 204 309 104 210 318 > mapply(function(x, y) {x * y}, 101:106, 1:3) [1] 101 204 309 104 210 318 Now with an S4 object: setClass("A", representation(aa="integer")) a <- new("A", aa=101:106) > length(a) [1] 1 Implementing length(): setMethod("length", "A", function(x) length(x@aa)) Testing length(): > length(a) # sanity check [1] 6 No [[ yet for those objects so the following error is expected: > mapply(function(x, y) {x * y}, a, rep(1:3, 2)) Error in dots[[1L]][[1L]] : this S4 class is not subsettable Implementing [[: setMethod("[[", "A", function(x, i, j, ...) x@aa[[i]]) Testing [[: > a[[1]] [1] 101 > a[[5]] [1] 105 Trying mapply again: > mapply(function(x, y) {x * y}, a, rep(1:3, 2)) [1] 101 202 303 101 202 303 Wrong. It looks like internally a[[1]] is always used instead of a[[i]]. The real problem it seems is that 'a' is treated as if it was of length 1: > mapply(function(x, y) {x * y}, a, 1:3) [1] 101 202 303 > mapply(function(x, y) {x * y}, a, 5) [1] 505 In other words, internal dispatch works for [[ but not for length(). Thanks, H. -- Hervé Pagès Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M1-B514 P.O. Box 19024 Seattle, WA 98109-1024 E-mail: hpa...@fhcrc.org Phone: (206) 667-5791 Fax:(206) 667-1319 Index: mapply.c === --- mapply.c (revision 61172) +++ mapply.c (working copy) @@ -32,14 +32,39 @@ int i, j, m, named, zero = 0; R_xlen_t *lengths, *counters, longest = 0; SEXP vnames, fcall = R_NilValue, mindex, nindex, tmp1, tmp2, ans; +static SEXP length_op = NULL; +/* Store the .Primitive for 'length' for DispatchOrEval to use. */ +if (length_op == NULL) { + SEXP R_lengthSymbol = install("length"); + length_op = eval(R_lengthSymbol, R_BaseEnv); + if (TYPEOF(length_op) != BUILTINSXP) { + length_op = NULL; + error("'length' is not a BUILTIN"); + } + R_PreserveObject(length_op); +} + m = length(varyingArgs); vnames = PROTECT(getAttrib(varyingArgs, R_NamesSymbol)); named = vnames != R_NilValue; lengths = (R_xlen_t *) R_alloc(m, sizeof(R_xlen_t)); for(i = 0; i < m; i++){ - lengths[i] = xlength(VECTOR_ELT(varyingArgs, i)); + int dispatch_ok = 0; + tmp1 = VECTOR_ELT(varyingArgs, i); + if (isObject(tmp1)) { + /* Looks like DispatchOrEval() needs a pairlist. We reproduce what + pairlist(tmp1) would do i.e. tmp2 <- as.pairlist(list(