[R-pkg-devel] S4 generic with variable naming of arguments
Dear colleagues, after testing one of my packages with students, I'm trying to improve the user interface, to make it even simpler and more robust. The package uses S4 classes and I was very happy with this, but my aim is now to allow non-named arguments with different ordering, depending on their class and with and 'speaking argument names', not simply x and y. It looks to me as this could be a FAQ and please excuse if I overlooked something, but I still wonder. Let's assume a generic like this: foo <- function(formula, data, grouping, ...) It is of course easy in S4 write methods that allow either 'foo(y ~ x, df)' or 'foo(data = df, grouping = g)' but I want to allow also 'foo(df, g)' This works easily in S3 (see below), but [how] can this also be done with S4 to avoid mixture of class systems in the package? Thanks a lot! Thomas ### Example ## foo <- function(formula, data, grouping = NULL, ...) UseMethod("foo") foo.formula <- function(formula, data, ...) { cat("formula method\n") } foo.data.frame <- function(data, grouping, ...) { cat("data method\n") } foo.default <- function(data, ...) cat("method for class", class(data), "not yet implemented\n") df <- data.frame(x=1:10, y=runif(10), groups=rep(c("a", "b"), 5)) foo(y~x, df)# easy in S4 foo(df, grouping="groups") # easy in S3, but how in S4? foo(1) ## __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
[R-pkg-devel] Linking an R package to the Python library
I am trying to create a self-contained R package wrapping Python that works cross platform and have not been able to do this on Windows. There is already an R package which calls Python, requiring Python to be installed on the target machine: https://github.com/cjgb/rPython-win. When the R package is built it successfully links to the resident Python dll. I retrieved the Python source code plus associated Visual Studio projects as described here: https://docs.python.org/devguide/setup.html I ran the Python 3.6 build and verified that rPython-win can link to the generated dll, as expected. In order to make a portable, self-contained R package, I changed the build to create a _static_ Python library as described in the file PCbuild\readme.txt. This creates a 31MB file "python36.lib" but when I try to build the rPython-win package under R i386 (and using the latest RTools) I get: gcc -m32 -shared -s -static-libgcc -o rPython.dll tmp.def pycall.o -LC:/cpython/PCbuild/win32 -lpython3stub -lpython36 -Ld:/RCompile/r-compiling/local/local323/lib/i386 -Ld:/RCompile/r-compiling/local/local323/lib -LC:/PROGRA~1/R/R-32~1.3/bin/i386 -lR C:/cpython/PCbuild/win32/python36.lib: *error adding symbols: File format not recognized* collect2.exe: error: ld returned 1 exit status no DLL was created ERROR: compilation failed for package 'rPython' I see some mention of the link error here: https://sourceware.org/bugzilla/show_bug.cgi?id=17910 It looks like a related bug was in binutils 2.25 on 2/27/2015. It seems like the fix would have made it into Rtools 3.3 since: 1) this page suggests that the aforementioned was resolved before the latest release of binutils, 2.25.1, 9/15/2015: https://sourceforge.net/projects/mingw/files/MinGW/Base/binutils/ 2) Installing Rtools 3.3, one can see that the binaries which are part of binutils (like ld.exe) are dated 9/22/2015. I don't know if MinGW is 'buggy', if I'm doing something wrong, and/or what to do to fix the link error. Is there anyone on this list with experience linking an R package to a static library built on Windows using Visual Studio? Any suggestions are appreciated! [[alternative HTML version deleted]] __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel