Re: [Rd] getConnection, R_outpstream_st
Hello, Maybe I should give more background about what we are trying to do with this. We (Dirk, Saptarshi and I) are interfacing R with the protocol buffer C++ library from google [1,2] . protocol buffers are google's data interchange format, designed to be efficient (much more efficient than XML) and language neutral. Google supports bindings to java, c++ and python, and there are dozens of third party bindings (perl, C, C#, ...) available. We are doing the one for R, allowing to create and manipulate protocol buffer messages from R. For example with this message type : package tutorial ; message Person { required int32 id = 1; required string name = 2; optional string email = 3; } you can create a message like this : message <- new( tutorial.Person, id = 0, name = "Romain", email = "francoisrom...@free.fr" ) We can also read/write messages from/to files : tutorial.Person$read( "somefile" ) serialize( message, "somefile" ) Now we'd like to be able to use the extensive IO support R provides (connections) and essentially read and write messages from and to arbitrary binary connections. Practically, it means calling this method of the google::protobuf::Message c++ class [3,4] bool Message::ParseFromIstream(istream * input) bool Message::SerializeToOstream( ostream * output) const This means we need to be able to build istream and ostream pointers working together with a binary R connection. It seemed to me from reading the code of serialize.c in R that we would be able to achieve this by sort of wrapping R_inpstream_st and R_outpstream_st as c++ streams. The only thing I cannot figure out at that point is how to access a connection pointer (Rconnection). From this : #ifdef NEED_CONNECTION_PSTREAMS /* The connection interface is not yet available to packages. To allow limited use of connection pointers this defines the opaque pointer type. */ #ifndef HAVE_RCONNECTION_TYPEDEF typedef struct Rconn *Rconnection; #define HAVE_RCONNECTION_TYPEDEF #endif void R_InitConnOutPStream(R_outpstream_t stream, Rconnection con, R_pstream_format_t type, int version, SEXP (*phook)(SEXP, SEXP), SEXP pdata); void R_InitConnInPStream(R_inpstream_t stream, Rconnection con, R_pstream_format_t type, SEXP (*phook)(SEXP, SEXP), SEXP pdata); #endif I get that if I do have a Rconnection, then I can initialize a R_outpstream_t and just use this, but I can't find a way to get one. The internal "getConnection" seems to do just this, but it is not accessible from packages. We'd appreciate any help. Romain [1] http://r-forge.r-project.org/projects/rprotobuf/ [2] http://code.google.com/p/protobuf/ [3] http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.message.html#Message.ParseFromIstream.details [4] http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.message.html#Message.SerializeToOstream.details On 11/07/2009 11:24 AM, Romain Francois wrote: Hello, I'm trying to use the limited connections api defined in Rinternals.h. I have code that looks like this (inspired from do_serializeToConn) : SEXP serialize_to_connection( SEXP xp, SEXP connection ){ Rconnection con ; struct R_outpstream_st out; R_pstream_format_t type = R_pstream_binary_format ; SEXP (*hook)(SEXP, SEXP) = NULL ; con = getConnection(Rf_asInteger(connection)); R_InitConnOutPStream(&out, con, type, 0, hook, R_NilValue ); return R_NilValue ; } The problem I have is that I cannot actually call getConnection since it is not part of the api. Is there another way to get the Rconnection that is associated with a number. Many thanks. Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/BcPw : celebrating R commit #5 |- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc `- http://tr.im/yw8E : New R package : sos __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] RSiteSearch and my R site
On 08/11/2009 7:23 AM, Jonathan Baron wrote: Duncan, This is not a problem with anything you just did, but I'm writing you and ccing r-devel, in case I am allowed to post there (which I think I'm not). R-devel is a public list, no problem posting here. The problem (in case this gets to r-devel) is that I need to have static html files for all packages, and static html ONLY for new packages. You have fixed the latter problem in the latest version of R-devel (11/08/09), in "R CMD INSTALL". Actually that fix broke some other things, so it's not in place at the moment. We'll get something there, but it might be different from what I did yesterday. > But when I install R-devel from source I cannot get all the html files. The configure script has an option for --enable-prebuilt-html, and this does build the static html files for about half of the standard packages! These include base, utils, tools, ..., but they do not include datasets, boot, cluster, ... I can of course work around this by using your new version of R CMD INSTALL after installing everything else. It does not wipe out the executables that are already installed (I think). But this might actually be a bug that was not intended. Yes, it sounds like it. Duncan __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] RSiteSearch and my R site
Duncan, This is not a problem with anything you just did, but I'm writing you and ccing r-devel, in case I am allowed to post there (which I think I'm not). The problem (in case this gets to r-devel) is that I need to have static html files for all packages, and static html ONLY for new packages. You have fixed the latter problem in the latest version of R-devel (11/08/09), in "R CMD INSTALL". But when I install R-devel from source I cannot get all the html files. The configure script has an option for --enable-prebuilt-html, and this does build the static html files for about half of the standard packages! These include base, utils, tools, ..., but they do not include datasets, boot, cluster, ... I can of course work around this by using your new version of R CMD INSTALL after installing everything else. It does not wipe out the executables that are already installed (I think). But this might actually be a bug that was not intended. Jon -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Summary methods
I've defined the following for objects of a class called jml summary.jml <- function(object, ...){ tab <- cbind(Estimate = coef(object), StdError = object$se, Infit = object$Infit, Outfit = object$Outfit) res <- list(call = object$call, coefficients = tab, N = nrow(object$Data), iter = object$Iterations) class(res) <- "summary.jml" res } print.summary.jml <- function(x, ...){ cat("Call:\n") print(x$call) cat("\n") cat("Number of iterations to completion:", x$iter, "\n") cat("Number of individuals used in estimation:", x$N, "\n") cat("\n") printCoefmat(x$coefficients) } Use of the methods on a fitted jml object yields: > summary(aa) Call: jml2.formula(formula = ~V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8 + V9 + V10, data = itemDat, bias = F) Number of iterations to completion: 6 Number of individuals used in estimation: 486 StdError Infit Outfit [1,] -0.380346 0.103002 1.007466 0.9935 [2,] 0.025939 0.104052 1.003050 1.0083 [3,] 2.563784 0.171174 0.941453 0.9414 [4,] -2.930519 0.156923 1.010786 1.0515 [5,] 1.139241 0.118932 0.978101 1.1424 [6,] -1.461751 0.111563 1.030612 1.2709 [7,] 0.486202 0.107986 1.008374 1.0394 [8,] -0.497102 0.103117 0.961431 0.9012 [9,] -0.486478 0.103099 1.001752 0.9829 [10,] 1.541029 0.129214 1.010011 0.9150 Two questions. First, why is the name of the first column empty instead of "Estimate" as I have specified in the summary method? Second, I am struggling to get the row names of the coefficients to align with the formula call. For example, instead of StdError Infit Outfit [1,] -0.380346 0.103002 1.007466 0.9935 I would prefer StdError Infit Outfit V1 -0.380346 0.103002 1.007466 0.9935 This also occurs in my print method print.jml <- function(x, digits = 2, ...){ cat("\nCall:\n", deparse(x$call), "\n\n", sep = "") cat("Coefficients:\n") print.default(format(coef(x), digits = digits), print.gap=2, quote = FALSE) invisible(x) } Which produces > win Call: jml2.default(dat = itemDat[, 1:10]) Coefficients: [,1] [1,] -0.38034638 [2,] 0.02593937 [3,] 2.56378422 [4,] -2.93051899 [5,] 1.13924076 [6,] -1.46175119 [7,] 0.48620247 [8,] -0.49710150 [9,] -0.48647770 [10,] 1.54102895 Thank you Harold > sessionInfo() R version 2.10.0 (2009-10-26) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] MASS_7.3-3 lme4_0.999375-32 Matrix_0.999375-31 lattice_0.17-26 [5] MiscPsycho_1.4 statmod_1.4.1 loaded via a namespace (and not attached): [1] grid_2.10.0 plink_1.2-2 tools_2.10.0 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] RcppTemplate
The Rcpp R/C++ object mapping library and package template has been updated on CRAN in package RcppTemplate. It allows you to work with R objects like data frames and zoo time series in C++ programs. R can call C++ functions, and C++ objects can call R functions, with parameters and return values of any of the most commonly used R data types (data frames, factors, time series, etc.). By using as.zoo, as.irts, as.xts, etc. it is possible to work with the other commonly used time series on the C++ side. The main design goal was improved performance. Dominick __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel