[Rd] bug in classesToAM()
Hi, I can't get the non-abbreviated class names of the rows and the cols of the Adjacency Matrix: setClass("ClassWithALongName") setClass("SubclassOfClassWithALongName", contains="ClassWithALongName") Trying all possible values for 'abbreviate' (with R-2.9.0): classesToAM("SubclassOfClassWithALongName", abbreviate=0) SubclassOfClassWithALongName ClassWithALongName SOCW0 1 CWAL0 0 classesToAM("SubclassOfClassWithALongName", abbreviate=1) SOCW CWAL SubclassOfClassWithALongName01 ClassWithALongName 00 classesToAM("SubclassOfClassWithALongName", abbreviate=2) SOCW CWAL SOCW01 CWAL00 classesToAM("SubclassOfClassWithALongName", abbreviate=3) SOCW CWAL SubclassOfClassWithALongName01 ClassWithALongName 00 This does not reflect what the man page is saying: "values 0, 1, 2, or 3 abbreviate neither, rows, columns or both". Cheers, H. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] wish list: automatic package installation
Dear list members, The release of R 2.9.0, reminds me of a long-standing nit that I have to pick. I prefer not to transfer and update all of the packages in my old library, because I see a new release of R as an opportunity to start with a clean slate. I'd rather install packages as I need them. My personal solution is to use the following function in place of library(): package <- function(package, dependencies=TRUE, ...){ package <- as.character(substitute(package)) if (!(package %in% .packages(all.available=TRUE))) install.packages(package, dependencies=dependencies) library(package, character.only=TRUE, ...) } I'm sure that this function could be improved, and possibly I've missed a facility that's already available. If not, it would be nice if the library() command automatically tried to download and install missing packages (perhaps if an option is set). Regards, John -- John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] speedup for as.matrix.dist
Hello, I am trying to patch as.matrix.dist to achieve some speedup. > m <- expand.grid( x = 1:20, y = 1:20, z = 1:20 ) > d <- dist( m ) > system.time( out <- stats:::as.matrix.dist( d ) ) user system elapsed 15.355 3.110 19.123 > system.time( out <- as.matrix.dist( d ) ) user system elapsed 3.153 0.480 3.782 The code below works if I deploy it in an additional package, but not when I patch the "stats" package, I get that kind of message: C symbol name "as_matrix_dist" not in load table Romain as.matrix.dist <- function(x, ...) { size <- as.integer(attr(x, "Size")) if( !is.numeric(x) ){ storage.mode(x) <- "numeric" } df <- .External( "as_matrix_dist", x = x, size = size, PACKAGE = "stats" ) labels <- attr(x, "Labels") dimnames(df) <- if(is.null(labels)) list(1L:size,1L:size) else list(labels,labels) df } /** * as.matrix.dist( d ) */ SEXP as_matrix_dist(SEXP args){ args = CDR( args ) ; SEXP x = CAR( args ); args = CDR( args ) ; SEXP size = CAR( args ); int i,j,k; int s = INTEGER(size)[0]; SEXP d ; PROTECT( d = allocVector( REALSXP, s*s) ); double element; for( i=0,k=0; ihttp://romainfrancois.blog.free.fr __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] print.closure at the R level
Hello, Could the code that auto prints a function/closure be extracted from print.c so that there would be a print.closure function. I would like to be able to mask a print.closure function so that I have a custom auto-print. One reason for that is I plan to have syntax highlighting within the R console. Romain -- Romain Francois Independent R Consultant +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] print.closure at the R level
On 18/04/2009 10:12 AM, Romain Francois wrote: Hello, Could the code that auto prints a function/closure be extracted from print.c so that there would be a print.closure function. I would like to be able to mask a print.closure function so that I have a custom auto-print. One reason for that is I plan to have syntax highlighting within the R console. The class of a closure is "function", so you'd want the method to be print.function. Currently that doesn't work for auto printing, so your suggestion is still interesting. (I'm not sure why auto printing is special here...) Duncan Murdoch __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] dotplot in a loop
Hi all, I'm a newbie R developer, am trying to dotplot a few graphs using a for loop. The following code works fine but once I wanna plot inside a loop, nothing happens. > for(i in 1:1){dotplot(y~x)} > y <- c(1,2,3) > x <- c('a','b','c') > dotplot(y~x) > for (i in 1:3) {dotplot(y~x)} (y and x depends on I in actual case) Nothing happens. I appreciate your advice on what is going wrong? Thanks. Best, Tony __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] dotplot in a loop
This is *definitely* a question for R-help, not for R-devel. Please do not misuse R-devel! Regards, Martin > "QZ" == Qifei Zhu > on Sat, 18 Apr 2009 12:34:38 -0400 writes: QZ> Hi all, QZ> I'm a newbie R developer, am trying to dotplot a few graphs using a for QZ> loop. QZ> The following code works fine but once I wanna plot inside a loop, nothing QZ> happens. >> for(i in 1:1){dotplot(y~x)} >> y <- c(1,2,3) >> x <- c('a','b','c') >> dotplot(y~x) >> for (i in 1:3) {dotplot(y~x)} (y and x depends on I in actual case) QZ> Nothing happens. QZ> I appreciate your advice on what is going wrong? Thanks. QZ> Best, QZ> Tony QZ> __ QZ> R-devel@r-project.org mailing list QZ> 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] dotplot in a loop
Ok, noted. Sorry for the confusion. -Original Message- From: Martin Maechler [mailto:maech...@stat.math.ethz.ch] Sent: Saturday, April 18, 2009 1:02 PM To: Qifei Zhu Cc: r-devel@r-project.org Subject: Re: [Rd] dotplot in a loop This is *definitely* a question for R-help, not for R-devel. Please do not misuse R-devel! Regards, Martin > "QZ" == Qifei Zhu > on Sat, 18 Apr 2009 12:34:38 -0400 writes: QZ> Hi all, QZ> I'm a newbie R developer, am trying to dotplot a few graphs using a for QZ> loop. QZ> The following code works fine but once I wanna plot inside a loop, nothing QZ> happens. >> for(i in 1:1){dotplot(y~x)} >> y <- c(1,2,3) >> x <- c('a','b','c') >> dotplot(y~x) >> for (i in 1:3) {dotplot(y~x)} (y and x depends on I in actual case) QZ> Nothing happens. QZ> I appreciate your advice on what is going wrong? Thanks. QZ> Best, QZ> Tony QZ> __ QZ> R-devel@r-project.org mailing list QZ> 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] print.closure at the R level
Duncan Murdoch wrote: On 18/04/2009 10:12 AM, Romain Francois wrote: Hello, Could the code that auto prints a function/closure be extracted from print.c so that there would be a print.closure function. I would like to be able to mask a print.closure function so that I have a custom auto-print. One reason for that is I plan to have syntax highlighting within the R console. The class of a closure is "function", so you'd want the method to be print.function. Currently that doesn't work for auto printing, so your suggestion is still interesting. (I'm not sure why auto printing is special here...) Duncan Murdoch Apparently, auto printing does not use the regular dispatch mechanism. See below: I'll make a more concrete proposal. This could be an opportunity to nail down as.character.function as well. Romain (from print.c) * print.default() -> do_printdefault (with call tree below) * * auto-printing -> PrintValueEnv * -> PrintValueRec * -> call print() for objects and PrintValueRec switches on the typeof : switch (TYPEOF(s)) { ... case CLOSXP: case LANGSXP: t = getAttrib(s, R_SourceSymbol); if (!isString(t) || !R_print.useSource) t = deparse1(s, 0, R_print.useSource | DEFAULTDEPARSE); for (i = 0; i < LENGTH(t); i++) Rprintf("%s\n", CHAR(STRING_ELT(t, i))); /* translated */ #ifdef BYTECODE if (TYPEOF(s) == CLOSXP && isByteCode(BODY(s))) Rprintf("\n", BODY(s)); #endif if (TYPEOF(s) == CLOSXP) { t = CLOENV(s); if (t != R_GlobalEnv) Rprintf("%s\n", EncodeEnvironment(t)); } break; -- Romain Francois Independent R Consultant +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] print.closure at the R level
Duncan Murdoch wrote: On 18/04/2009 10:12 AM, Romain Francois wrote: Hello, Could the code that auto prints a function/closure be extracted from print.c so that there would be a print.closure function. I would like to be able to mask a print.closure function so that I have a custom auto-print. One reason for that is I plan to have syntax highlighting within the R console. The class of a closure is "function", so you'd want the method to be print.function. Currently that doesn't work for auto printing, so your suggestion is still interesting. (I'm not sure why auto printing is special here...) Duncan Murdoch The attached patch implements exposing the print.function at the R level. Romain -- Romain Francois Independent R Consultant +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr Index: src/include/Internal.h === --- src/include/Internal.h (revision 48350) +++ src/include/Internal.h (working copy) @@ -370,6 +370,7 @@ SEXP do_printdefault(SEXP, SEXP, SEXP, SEXP); SEXP do_printDeferredWarnings(SEXP, SEXP, SEXP, SEXP); SEXP do_printdf(SEXP, SEXP, SEXP, SEXP); +SEXP do_printfunction(SEXP, SEXP, SEXP, SEXP); SEXP do_prmatrix(SEXP, SEXP, SEXP, SEXP); SEXP do_proctime(SEXP, SEXP, SEXP, SEXP); SEXP do_psort(SEXP, SEXP, SEXP, SEXP); Index: src/library/base/R/print.R === --- src/library/base/R/print.R (revision 48350) +++ src/library/base/R/print.R (working copy) @@ -85,3 +85,8 @@ print(noquote(cbind("_"=unlist(x))), ...) `[.simple.list` <- `[.listof` + +print.function <- function( x, useSource=TRUE, ...){ + .Internal( print.function( x, useSource, ... ) ) +} + Index: src/main/names.c === --- src/main/names.c (revision 48350) +++ src/main/names.c (working copy) @@ -631,6 +631,7 @@ {"readline", do_readln, 0, 11, 1, {PP_FUNCALL, PREC_FN, 0}}, {"menu", do_menu, 0, 11, 1, {PP_FUNCALL, PREC_FN, 0}}, {"print.default",do_printdefault,0, 111, 9, {PP_FUNCALL, PREC_FN, 0}}, +{"print.function",do_printfunction,0, 111, 3, {PP_FUNCALL, PREC_FN, 0}}, {"prmatrix", do_prmatrix, 0, 111, 6, {PP_FUNCALL, PREC_FN, 0}}, {"invisible", do_invisible, 0, 101, 1, {PP_FUNCALL, PREC_FN, 0}}, {"gc", do_gc, 0, 11, 2, {PP_FUNCALL, PREC_FN, 0}}, Index: src/main/print.c === --- src/main/print.c (revision 48350) +++ src/main/print.c (working copy) @@ -154,6 +154,34 @@ return x; }/* do_prmatrix */ + +/* .Internal( print.function( f,useSource,... ) ) */ +SEXP attribute_hidden do_printfunction( SEXP call, SEXP op, SEXP args, SEXP rho){ + SEXP s,t; + Rboolean useSource = TRUE; + s=CAR(args); + args = CDR(args); useSource=asLogical(CAR(args)); + + int i; + if( ! (TYPEOF(s) == CLOSXP || TYPEOF(s) == LANGSXP ) ) return R_NilValue; + t = getAttrib(s, R_SourceSymbol); + if (!isString(t) || !useSource) + t = deparse1(s, 0, useSource | DEFAULTDEPARSE); + for (i = 0; i < LENGTH(t); i++) + Rprintf("%s\n", CHAR(STRING_ELT(t, i))); /* translated */ +#ifdef BYTECODE + if (TYPEOF(s) == CLOSXP && isByteCode(BODY(s))) + Rprintf("\n", BODY(s)); +#endif + if (TYPEOF(s) == CLOSXP) { + t = CLOENV(s); + if (t != R_GlobalEnv) + Rprintf("%s\n", EncodeEnvironment(t)); + } + return R_NilValue; +} + + /* .Internal(print.default(x, digits, quote, na.print, print.gap, right, max, useS4)) */ SEXP attribute_hidden do_printdefault(SEXP call, SEXP op, SEXP args, SEXP rho) @@ -646,23 +674,15 @@ case EXPRSXP: PrintExpression(s); break; +case LANGSXP: case CLOSXP: -case LANGSXP: - t = getAttrib(s, R_SourceSymbol); - if (!isString(t) || !R_print.useSource) - t = deparse1(s, 0, R_print.useSource | DEFAULTDEPARSE); - for (i = 0; i < LENGTH(t); i++) - Rprintf("%s\n", CHAR(STRING_ELT(t, i))); /* translated */ -#ifdef BYTECODE - if (TYPEOF(s) == CLOSXP && isByteCode(BODY(s))) - Rprintf("\n", BODY(s)); -#endif - if (TYPEOF(s) == CLOSXP) { - t = CLOENV(s); - if (t != R_GlobalEnv) - Rprintf("%s\n", EncodeEnvironment(t)); + { + SEXP call; + PROTECT( call = lang2(install("print.function"), s)); + eval(call,env); + UNPROTECT(1); + break; } - break; case ENVSXP: Rprintf("%s\n", EncodeEnvironment(s)); break; @@ -905,7 +925,13 @@ PROTECT(call = lang2(install("print"), s)); eval(call, env); UNPROTECT(1); -} else PrintValueRec(s, env); +} else if( TYPEOF(s) == CLOSXP || TYPEOF(s) == LANGSXP){ + SEXP call; + PROTECT(call = lang2(install("print.function"), s)); + eval(call,env); + } else { + PrintValueRec(s, env); + } UNPROTECT(1); } @@ -1009,3 +1035,4 @@ buf[6] = '\0'; error(_("BLAS/LAPACK routine '%6s' gave error code %d"), buf, -(*info)); } + __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-dev
Re: [Rd] bug in classesToAM()
Yes, thanks. Should be fixed now in r-devel and 2.9.0 patched. John hpa...@fhcrc.org wrote: Hi, I can't get the non-abbreviated class names of the rows and the cols of the Adjacency Matrix: setClass("ClassWithALongName") setClass("SubclassOfClassWithALongName", contains="ClassWithALongName") Trying all possible values for 'abbreviate' (with R-2.9.0): classesToAM("SubclassOfClassWithALongName", abbreviate=0) SubclassOfClassWithALongName ClassWithALongName SOCW0 1 CWAL0 0 classesToAM("SubclassOfClassWithALongName", abbreviate=1) SOCW CWAL SubclassOfClassWithALongName01 ClassWithALongName 00 classesToAM("SubclassOfClassWithALongName", abbreviate=2) SOCW CWAL SOCW01 CWAL00 classesToAM("SubclassOfClassWithALongName", abbreviate=3) SOCW CWAL SubclassOfClassWithALongName01 ClassWithALongName 00 This does not reflect what the man page is saying: "values 0, 1, 2, or 3 abbreviate neither, rows, columns or both". Cheers, H. __ 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] export C++ array to R
Hi, I am a newbie on C++ Right now I have an array of doubles in C++. Is there a way to "export" that array into R? Of course, I can allocate the memory block first using "allocVector" and copying the array contents one by one. But, what if that array is fairly large? Copying doesn't look that efficient. I was thinking of setting the data pointer(DATAPTR) point to that array, and adjust the LENGTH of SEXP. But I don't know how to do that. Any comment/answer would be much appreciated. Thank you. -- View this message in context: http://www.nabble.com/export-C%2B%2B-array-to-R-tp23110405p23110405.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