[Rd] Problem with R 3.0.0
Dear R developer, I am an R user and am currently having a problem with versions of R 3.0.0. We build larger correlation matrices of 3 with pairwise correlations made. We have been using a line of code simMat=bicor(datExpr1,use=p) To build the similarity matrix with datExpr1 being a matrix with genes as columns (3) and rows being samples. This code works fine on an iMac running OSX 10.8.5 and using R 2.15.2 and the Rblas library. When I try to run the same code with R version 3.0.0 and 3.0.1 it only partially builds the matrix. It will return correlations for samples 1:11262 but from 11262:3 the matrix is full of 0's. We would like to be able to use R 3.0.0 to allow us to build larger correlation matrices on our cluster but we can't use it at the moment due to this problem. My colleague has previously had a similar issue when using snow leopard and this was to do with a compatibility issue between snow leopard and the veclib. Has something changed in version 3.0.0 to give an incompatibility with the veclib? Many thanks Sam Samuel Shelton, Ph.D. Postdoctoral Researcher, The Oldham Lab, The institute of Regeneration Medicine, University of California San Francisco, San Francisco, CA 94143 email: shelt...@stemcell.ucsf.edu [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Problem with R 3.0.0
On Aug 19, 2013, at 20:53 , Shelton, Samuel wrote: Dear R developer, I am an R user and am currently having a problem with versions of R 3.0.0. We build larger correlation matrices of 3 with pairwise correlations made. We have been using a line of code simMat=bicor(datExpr1,use=p) What is bicor()? From the WGCNA package? Perhaps the package is doing something incompatible with the long vector support in R 3.0.0. You need to report such queries to the maintainer. So far we have no evidence that the bug is in R itself, and you're not giving us anything reproducible to investigate. To build the similarity matrix with datExpr1 being a matrix with genes as columns (3) and rows being samples. This code works fine on an iMac running OSX 10.8.5 and using R 2.15.2 and the Rblas library. When I try to run the same code with R version 3.0.0 and 3.0.1 it only partially builds the matrix. It will return correlations for samples 1:11262 but from 11262:3 the matrix is full of 0's. We would like to be able to use R 3.0.0 to allow us to build larger correlation matrices on our cluster but we can't use it at the moment due to this problem. My colleague has previously had a similar issue when using snow leopard and this was to do with a compatibility issue between snow leopard and the veclib. Has something changed in version 3.0.0 to give an incompatibility with the veclib? This seems entirely speculative. Please stick to the facts. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Problem with R 3.0.0
Hi Sam, I assume you mean that correlation for _genes_ (not samples) 11262:3 is 0? I am the maintainer of the WGCNA package but unfortunately I don't have access to a Mac big enough to try 3x3 correlation matrix, but I would be thankful if you could try reproducing the problem with smaller matrices (e.g. 2x2) and try to produce a small reproducible example by generating the data using say rnorm, say like this: nGenes = 2 # as small as possible that still produces the error nSamples = 100 datExpr1 = matrix(rnorm(nSamples * nGenes), nSamples, nGenes) simMat = bicor(datExpr1, use = 'p') Best, Peter On Mon, Aug 19, 2013 at 11:53 AM, Shelton, Samuel shelt...@stemcell.ucsf.edu wrote: Dear R developer, I am an R user and am currently having a problem with versions of R 3.0.0. We build larger correlation matrices of 3 with pairwise correlations made. We have been using a line of code simMat=bicor(datExpr1,use=p) To build the similarity matrix with datExpr1 being a matrix with genes as columns (3) and rows being samples. This code works fine on an iMac running OSX 10.8.5 and using R 2.15.2 and the Rblas library. When I try to run the same code with R version 3.0.0 and 3.0.1 it only partially builds the matrix. It will return correlations for samples 1:11262 but from 11262:3 the matrix is full of 0's. We would like to be able to use R 3.0.0 to allow us to build larger correlation matrices on our cluster but we can't use it at the moment due to this problem. My colleague has previously had a similar issue when using snow leopard and this was to do with a compatibility issue between snow leopard and the veclib. Has something changed in version 3.0.0 to give an incompatibility with the veclib? Many thanks Sam Samuel Shelton, Ph.D. Postdoctoral Researcher, The Oldham Lab, The institute of Regeneration Medicine, University of California San Francisco, San Francisco, CA 94143 email: shelt...@stemcell.ucsf.edu [[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] Problem with R 3.0.0
On Tue, Aug 20, 2013 at 9:23 AM, peter dalgaard pda...@gmail.com wrote: What is bicor()? From the WGCNA package? Perhaps the package is doing something incompatible with the long vector support in R 3.0.0. You need to report such queries to the maintainer. The maintainer is reporting for duty :) The version of WGCNA currently on CRAN uses .C to call compiled code. If I read the manuals right, long vectors are not allowed in .C calls. In my .C calls I use explicit type casts (as.integer, as.double etc) for all arguments. Once we see a reproducible example, we can figure out the problem. Peter __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Problem with R 3.0.0
Hi Samuel, WGCNA currently does not support calculations with matrices larger than the old R limit, and it will take some time to update it to support the large matrices. Furthermore, WGCNA relies on other functions (most notably hclust) that would have to be updated as well to support long vectors. In the meantime I suggest using the blockwise functions to handle large data sets, or, if possible, reducing the number of genes to less than the old limit of 46340 or so. Sorry I can't be of more help. Best, Peter On Tue, Aug 20, 2013 at 10:42 AM, Shelton, Samuel shelt...@stemcell.ucsf.edu wrote: Hi all, Thanks for getting back to me. We would like to move over to v3.0.0 on our cluster so that we can build matrices larger than 46300*46300 (limit in R 3.0.0) but so far we can't get things to work with R v3.0.0 and higher. I am trying to trouble shoot at the moment and I am now thinking that the problem is actually with the diag function that has been rewritten in version 3.0.0. The problem is definitely with the diag function and it does not occur on smaller matrices (2*2) and I think it maybe a bug. This illustrates the problem: This was done on an iMac i5 with OSX 10.8.5 16GB Ram and with R 3.0.1 (but I do see the same for 3.0.0). This does not occur when I run it with R 2.15.2. mat1=matrix(rexp(2^2), 2) mat1[1:10,1:10] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 0.1829090 0.39867734 0.80499126 4.1746377 0.20717066 1.1477365 0.469843567 2.57767543 0.17449595 0.01949358 [2,] 0.5731522 0.15835939 0.29165029 0.6781249 0.64553728 2.4438404 2.140374938 0.40091195 0.51201369 0.98904490 [3,] 0.3250310 0.09934147 0.79962549 0.4933385 0.30473422 0.4556765 0.002640034 0.90606861 2.58772944 0.89884208 [4,] 1.4195017 0.16082660 0.01377838 0.2115803 1.43992672 0.3883675 0.040903805 0.51011305 0.41998024 0.44209926 [5,] 0.8328441 1.10335604 0.11875332 0.1600287 0.1724 0.3388678 3.206179119 0.52170966 1.03084845 0.05843232 [6,] 1.3179906 0.76376188 1.24231798 0.9424030 0.04440514 1.0237664 2.547528816 1.35629450 0.87983354 0.25236343 [7,] 0.6990544 1.17003075 0.66063936 0.8632534 0.28965611 0.6718020 1.137348735 0.08371053 0.23144290 0.18915132 [8,] 0.9908026 1.20471979 0.08816010 0.2652131 0.03537790 0.3295816 0.144371435 3.03299285 0.09728111 0.39890260 [9,] 0.9557305 0.29196500 0.43955758 0.7332643 2.03457020 0.5858431 2.437192399 0.34689557 0.02039205 0.54898488 [10,] 3.7220703 0.13572389 0.1673 0.5683698 1.79209016 1.3495723 0.571159401 0.63375850 0.63221987 1.32840290 mat1[19990:2,19990:2] [,1] [,2] [,3] [,4] [,5][,6] [,7] [,8] [,9] [,10] [,11] [1,] 1.7910910 0.5719982 0.38689588 1.2157545685 0.8530179 1.464105574 0.5986705 1.1623393 0.55244563 0.1770146 0.4326310 [2,] 0.2862914 1.5267870 0.98214645 0.0004617244 0.6395319 0.075217874 0.6725620 0.2403549 0.08436217 0.1435451 0.7487862 [3,] 2.0492301 0.7216115 0.16951284 0.2726676762 2.1893806 1.202518385 0.9897710 1.4813026 2.42517705 0.3398811 0.7285074 [4,] 0.6538994 0.2437594 2.08848881 0.3917212249 0.4441824 0.433749415 1.3022991 1.3695241 0.07057642 0.4296937 2.9307556 [5,] 2.3688094 2.3970048 0.03545232 0.5986997508 0.8914097 0.497023176 0.4210650 1.5337767 0.01141066 1.1562830 1.0572076 [6,] 2.0626934 0.6186995 0.99197835 1.4794321654 0.1549314 1.296227000 0.2790942 0.9327613 0.84131377 0.8782590 0.3279970 [7,] 1.2423823 0.2385994 0.11390071 2.0745023842 1.9152523 0.754186281 1.5474078 2.5899490 5.19298969 1.4680934 1.0537164 [8,] 1.3657070 1.9502828 1.07681438 0.9339731540 1.7532474 0.186193421 1.8699504 1.9187339 5.13248671 0.4621520 0.4753582 [9,] 0.6512000 0.5104660 0.17820166 0.3965162944 0.0919119 0.187808660 0.7391137 0.1574844 0.65985494 0.4066742 0.8072494 [10,] 0.7435028 1.1395666 2.46096009 0.7060164691 1.7965986 0.008278685 0.4642319 0.1582297 1.71676326 0.3662139 0.7864957 [11,] 0.3537041 0.6622001 2.01642141 1.8225423060 0.3295436 1.260737179 0.8430396 0.5132811 0.30547431 1.6088725 0.4001791 diag(mat1)=0 mat1[1:10,1:10] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 0.000 0.39867734 0.80499126 4.1746377 0.20717066 1.1477365 0.469843567 2.57767543 0.17449595 0.01949358 [2,] 0.5731522 0. 0.29165029 0.6781249 0.64553728 2.4438404 2.140374938 0.40091195 0.51201369 0.98904490 [3,] 0.3250310 0.09934147 0. 0.4933385 0.30473422 0.4556765 0.002640034 0.90606861 2.58772944 0.89884208 [4,] 1.4195017 0.16082660 0.01377838 0.000 1.43992672 0.3883675 0.040903805 0.51011305 0.41998024 0.44209926 [5,] 0.8328441 1.10335604 0.11875332 0.1600287 0. 0.3388678 3.206179119 0.52170966 1.03084845 0.05843232 [6,] 1.3179906 0.76376188 1.24231798 0.9424030 0.04440514 0.000 2.547528816 1.35629450
[Rd] Extending suggestion for stopifnot
I am using a variant of stopifnot a lot. can I suggest that base R extends its functionality? I know how to do this for myself. this is a suggestion for beginners and students. I don't think it would break anything. first, I think it would be more useful if it had an optional character string, so users could write stopifnot( is.matrix(m), m is not a matrix ) this would mean that stopifnot would have to detect whether the last argument is a string. (I think stopifnot should have had only one condition, and one should have used all() to test multiple conditions, but this is a bridge that was already crossed.) upon failure, stopifnot should print the character string. that's it. A second enhancement would be a smart string, which knows that everything inside {{...}} should be evaluated. stopifnot( is.matrix(m), m is not a matrix, but a {{class(m)}} ) my own programming variant looks even nicer, is.matrix(m) %or% m is not a matrix but a {{class(m)}} but requesting base R to add the %and% and %or% (or, better yet, 'and' and 'or') operators by default would be pushing my luck. /iaw Ivo Welch (ivo.we...@gmail.com) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Extending suggestion for stopifnot
On Wed, Aug 21, 2013 at 12:11 AM, ivo welch ivo.we...@anderson.ucla.edu wrote: I am using a variant of stopifnot a lot. can I suggest that base R extends its functionality? I know how to do this for myself. this is a suggestion for beginners and students. I don't think it would break anything. first, I think it would be more useful if it had an optional character string, so users could write stopifnot( is.matrix(m), m is not a matrix ) How is this better/nicer/more preferable than, say, if (!is.matrix(m)) stop(m is not a matrix) ? I think stopifnot() is mostly meant for regression tests and sanity checks, and should not be used instead of stop() if you want nicely formatted error messages. -Deepayan this would mean that stopifnot would have to detect whether the last argument is a string. (I think stopifnot should have had only one condition, and one should have used all() to test multiple conditions, but this is a bridge that was already crossed.) upon failure, stopifnot should print the character string. that's it. A second enhancement would be a smart string, which knows that everything inside {{...}} should be evaluated. stopifnot( is.matrix(m), m is not a matrix, but a {{class(m)}} ) my own programming variant looks even nicer, is.matrix(m) %or% m is not a matrix but a {{class(m)}} but requesting base R to add the %and% and %or% (or, better yet, 'and' and 'or') operators by default would be pushing my luck. /iaw Ivo Welch (ivo.we...@gmail.com) __ 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] R-devel Digest, Vol 126, Issue 18
Thank you, it does work now indeed. My platform is 32 bit. -- Txikiak On 08/20/2013 12:00 PM, r-devel-requ...@r-project.org wrote: Date: Mon, 19 Aug 2013 14:08:33 +0100 From: Prof Brian Ripley rip...@stats.ox.ac.uk To: r-devel@r-project.org Subject: Re: [Rd] Issues in installing R-devel Message-ID: 521218d1.1050...@stats.ox.ac.uk Content-Type: text/plain; charset=ISO-8859-1; format=flowed Please try again: this has already been reported and fixed. BTW, you did not follow the posting guide and report your platform. This issue was only for 32-bit builds. On 19/08/2013 11:34, Arrain Txikiak wrote: Dear list, I have tried to compile and install the development version of R, but met some problems I'm not quite sure how to resolve. I have downloaded the code from your repository, configured, and tried to compile using the makefile, as follows: [atxi@aquario R]$ svn co http://svn.r-project.org/R/trunk [atxi@aquario R]$ cd trunk [atxi@aquario R]$ ./tools/rsync-recommended [atxi@aquario R]$ ./configure --enable-R-shlib [atxi@aquario R]$ make I'm getting the following error: gcc -std=gnu99 -Wl,--export-dynamic -fopenmp -L/usr/local/lib -o R.bin Rmain.o -L../../lib -lR -lRblas ../../lib/libR.so: undefined reference to `SHORT_VEC_LENGTH' collect2: ld returned 1 exit status This does not seem to be a missing dependency, as the complaint is about something included in the R code. I had previously successfully installed R-devel using the exact same commands on the same machine. What am I doing wrong? In advance thank you for support. -- Txikiak __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Extending suggestion for stopifnot
On Aug 20, 2013, at 14:41, ivo welch ivo.we...@anderson.ucla.edu wrote: A second enhancement would be a smart string, which knows that everything inside {{...}} should be evaluated. I think one the HTML templating libraries (whisker or mustache or some such) provides something not unlike this. Perhaps take a look. stopifnot( is.matrix(m), m is not a matrix, but a {{class(m)}} ) my own programming variant looks even nicer, is.matrix(m) %or% m is not a matrix but a {{class(m)}} but requesting base R to add the %and% and %or% (or, better yet, 'and' and 'or') operators by default would be pushing my luck. Does %or% throw an error or is this wrapped in something else? The former seems rather perl-ish, but the latter might suggest you look into the || and operators if you only know their single counterparts. Michael /iaw Ivo Welch (ivo.we...@gmail.com) __ 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] Extending suggestion for stopifnot
On Tue, Aug 20, 2013 at 11:41 AM, ivo welch ivo.we...@anderson.ucla.edu wrote: I am using a variant of stopifnot a lot. can I suggest that base R extends its functionality? I know how to do this for myself. this is a suggestion for beginners and students. I don't think it would break anything. first, I think it would be more useful if it had an optional character string, so users could write stopifnot( is.matrix(m), m is not a matrix ) this would mean that stopifnot would have to detect whether the last argument is a string. (I think stopifnot should have had only one condition, and one should have used all() to test multiple conditions, but this is a bridge that was already crossed.) upon failure, stopifnot should print the character string. that's it. A second enhancement would be a smart string, which knows that everything inside {{...}} should be evaluated. stopifnot( is.matrix(m), m is not a matrix, but a {{class(m)}} ) I think using a function (in this case paste) is cleaner: paste(m is not a matrix, but a, class(m)) It avoids adding a new convention (evaluate everything between {{ }}) and has additional arguments. my own programming variant looks even nicer, is.matrix(m) %or% m is not a matrix but a {{class(m)}} In R you can write it as is.matrix(m) || stop(m is not a matrix but a , class(m)) Examples: m = 1 is.matrix(m) || stop(m is not a matrix but a , class(m)) Error: m is not a matrix but a numeric m = matrix(0,2,2) is.matrix(m) || stop(m is not a matrix but a , class(m)) [1] TRUE But the construct if (!is.matrix(m)) stop(m is not a matrix but a , class(m)) is more readable for people not used to Pearl. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Extending suggestion for stopifnot
If all you care about is emulating static type checking, then you can also accomplish the same thing with lambda.r using type constraints on function definitions. e.g. f(m) %::% matrix : matrix f(m) %as% { m } f(as.data.frame(matrix(rnorm(12),nrow=3))) Error in UseFunction(f, ...) : No valid function for 'f(data.frame)' f(1) Error in UseFunction(f, ...) : No valid function for 'f(1)' f function [[1]] f(m) %::% matrix:matrix f(m) %as% … On Aug 20, 2013, at 4:36 PM, Peter Langfelder peter.langfel...@gmail.com wrote: On Tue, Aug 20, 2013 at 11:41 AM, ivo welch ivo.we...@anderson.ucla.edu wrote: I am using a variant of stopifnot a lot. can I suggest that base R extends its functionality? I know how to do this for myself. this is a suggestion for beginners and students. I don't think it would break anything. first, I think it would be more useful if it had an optional character string, so users could write stopifnot( is.matrix(m), m is not a matrix ) this would mean that stopifnot would have to detect whether the last argument is a string. (I think stopifnot should have had only one condition, and one should have used all() to test multiple conditions, but this is a bridge that was already crossed.) upon failure, stopifnot should print the character string. that's it. A second enhancement would be a smart string, which knows that everything inside {{...}} should be evaluated. stopifnot( is.matrix(m), m is not a matrix, but a {{class(m)}} ) I think using a function (in this case paste) is cleaner: paste(m is not a matrix, but a, class(m)) It avoids adding a new convention (evaluate everything between {{ }}) and has additional arguments. my own programming variant looks even nicer, is.matrix(m) %or% m is not a matrix but a {{class(m)}} In R you can write it as is.matrix(m) || stop(m is not a matrix but a , class(m)) Examples: m = 1 is.matrix(m) || stop(m is not a matrix but a , class(m)) Error: m is not a matrix but a numeric m = matrix(0,2,2) is.matrix(m) || stop(m is not a matrix but a , class(m)) [1] TRUE But the construct if (!is.matrix(m)) stop(m is not a matrix but a , class(m)) is more readable for people not used to Pearl. __ 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] Extending suggestion for stopifnot
thx, deepayan: how is stopifnot better than if (!all(...)) stop() given that we have stopifnot() and I have seen it used often, I think my two suggestions would make it better. thx, michael: the %and% and %or% constructs are indeed relics of my perl background. my own definition is `%and%` - function(e1, e2) { if (e1) { if (is.character(e2)) abort.estring(e2) else eval(e2) } } it's syntactic sugar. my abort.estring() function prints the character as n estring() [extended string, see below] and exits. it can probably be written a lot better. remember, I am not an expert. thx, peter: the estring has the advantage of having it all in one string, which allows me to say, e.g., (x) %or% x is not true but {{x}} the comma here does not work. it basically becomes an interpolated string, just like the construct x is $x in perl. thx, bill: ensureThat() is not a base R function. uggh---I think you are right on precedence. I always use parens around my conditions. old C habit from decades ago, so I never ran into this problem. if() is good enough. my main suggestion was adding an optional message at the end of stopifnot(), and possibly extended (interpolated) strings. thx, brian: I think of lambda.r as being more heavyweight and requiring a modestly steeper learning curve. if it was standard in base R, I would definitely switch to it. I think we want a system that my students are taught to use from day 1. in sum, I agree that one accomplish the functionality in base R. my initial suggestion was very simple and small: (1) adding an optional character string at the end of an existing function, stopifnot(). (2) I think estrings (that behave like characters but are interpolated before printout) are useful in the same way perl interpolated strings are useful. this would be a bigger change. some people would like it. others don't see the advantage. I think the benefits would outweigh the costs. (3) I just mentioned %and% and %or% as an aside. it this is definitely a bigger change, where we can all agree to disagree whether we like this in code or not. just ignore #3. best, /iaw estring - function(e2, N.UP =2) { rx - (?=\\{\\{).*?(?=\\}\\}) match - gregexpr(rx, e2, perl=TRUE) syntax - regmatches(e2, match)[[1]] syntax - lapply(syntax, parse, file=, n=NULL) ## syntax-lapply(syntax, eval.parent, n=N.UP) r - tryCatch( syntax-lapply(syntax, eval.parent, n=N.UP), error= function(e) NULL ) if (is.null(r)) r - tryCatch( syntax-lapply(syntax, eval.parent, n=N.UP+1), error= function(e) NULL ) if (is.null(r)) r - tryCatch( syntax-lapply(syntax, eval.parent, n=N.UP-1), error= function(e) NULL ) if (is.null(r)) r - tryCatch( syntax-lapply(syntax, eval.parent, n=N.UP-2), error= function(e) unknown variable ) ## the return is now ignored. if we cannot recognize the syntax, we just leave it. s- unlist(sys.calls()) if (length(s)1) cat(Function ', as.character(s[[length(s)-N.UP+1]]), ':\n\t, sep=) else cat([GlobalEnv]:\t) regmatches(e2, match) - %s do.call(sprintf, c(fmt=e2, '...'=syntax) ) } Ivo Welch (ivo.we...@gmail.com) http://www.ivo-welch.info/ J. Fred Weston Professor of Finance Anderson School at UCLA, C519 Director, UCLA Anderson Fink Center for Finance and Investments Free Finance Textbook, http://book.ivo-welch.info/ Editor, Critical Finance Review, http://www.critical-finance-review.org/ On Tue, Aug 20, 2013 at 2:14 PM, Brian Rowe r...@muxspace.com wrote: If all you care about is emulating static type checking, then you can also accomplish the same thing with lambda.r using type constraints on function definitions. e.g. f(m) %::% matrix : matrix f(m) %as% { m } f(as.data.frame(matrix(rnorm(12),nrow=3))) Error in UseFunction(f, ...) : No valid function for 'f(data.frame)' f(1) Error in UseFunction(f, ...) : No valid function for 'f(1)' f function [[1]] f(m) %::% matrix:matrix f(m) %as% … On Aug 20, 2013, at 4:36 PM, Peter Langfelder peter.langfel...@gmail.com wrote: On Tue, Aug 20, 2013 at 11:41 AM, ivo welch ivo.we...@anderson.ucla.edu wrote: I am using a variant of stopifnot a lot. can I suggest that base R extends its functionality? I know how to do this for myself. this is a suggestion for beginners and students. I don't think it would break anything. first, I think it would be more useful if it had an optional character string, so users could write stopifnot( is.matrix(m), m is not a matrix ) this would mean that stopifnot would have to detect whether the last argument is a string. (I think stopifnot should have had only one condition, and one should have used all() to test multiple conditions, but this is a bridge that was already crossed.) upon failure, stopifnot should print the character string. that's it. A second enhancement would be a smart string, which knows that everything inside {{...}} should be evaluated. stopifnot( is.matrix(m), m is not a matrix, but a {{class(m)}} )
Re: [Rd] Extending suggestion for stopifnot
On Tue, Aug 20, 2013 at 6:00 PM, ivo welch ivo.we...@gmail.com wrote: character string at the end of an existing function, stopifnot(). (2) I think estrings (that behave like characters but are interpolated before printout) are useful in the same way perl interpolated strings are useful. The gsubfn package has string interpolation somewhat like perl. Preface a function call with fn$ and then back ticks and $ are interpolated. library(gsubfn) fn$identity(pi is $pi) library(sqldf) fn$sqldf(select * from BOD where Time $pi) fn$stop(class is `class(pi)`) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Extending suggestion for stopifnot
functionality is nice. syntax is weird. I think I would have preferred an interpolate function call. stop( i(class is `class(pi)` and $pi) ) three typing letters, too, and more logical. most importantly, I wish we had some form of this in base R from the outset--whatever it is--so that my students get used to using the standard from the outset. [the {{...}} had the advantage of being unlikely to break anything. perl has it nicely done--- is interpolated, ' is not. but this is a bridge that we crossed long ago in R. it would break too much.] best, /iaw Ivo Welch (ivo.we...@gmail.com) http://www.ivo-welch.info/ J. Fred Weston Professor of Finance Anderson School at UCLA, C519 Director, UCLA Anderson Fink Center for Finance and Investments Free Finance Textbook, http://book.ivo-welch.info/ Editor, Critical Finance Review, http://www.critical-finance-review.org/ On Tue, Aug 20, 2013 at 3:28 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Tue, Aug 20, 2013 at 6:00 PM, ivo welch ivo.we...@gmail.com wrote: character string at the end of an existing function, stopifnot(). (2) I think estrings (that behave like characters but are interpolated before printout) are useful in the same way perl interpolated strings are useful. The gsubfn package has string interpolation somewhat like perl. Preface a function call with fn$ and then back ticks and $ are interpolated. library(gsubfn) fn$identity(pi is $pi) library(sqldf) fn$sqldf(select * from BOD where Time $pi) fn$stop(class is `class(pi)`) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Extending suggestion for stopifnot
first, I think it would be more useful if it had an optional character string, so users could write stopifnot( is.matrix(m), m is not a matrix ) Another option is to just generate better error messages automatically, e.g.: library(assertthat) x - 1:10 assert_that(is.matrix(x)) Error: x is not a matrix Hadley -- Chief Scientist, RStudio http://had.co.nz/ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Extending suggestion for stopifnot
On 08/20/2013 11:41 AM, ivo welch wrote: A second enhancement would be a smart string, which knows that everything inside {{...}} should be evaluated. stopifnot( is.matrix(m), m is not a matrix, but a {{class(m)}} ) a variant with more traditional syntax might be if (!is.matrix(m)) stopf(m is not a matrix, but a '%s', class(m)) or stopifnotf(is.matrix(m), m is not a matrix, but a '%s', class(m)) where stopf is analogous to sprintf but signalling the corresponding condition (perhaps taking the opportunity to strwrap to getOption(width)). This would work well with gettextf to allow for translation. An imperfect implementation (call. is incorrect, for example) is .msg - function(fmt, ..., domain=NULL, width=getOption(width)) ## Use this helper to format all error / warning / message text { txt - strwrap(gettextf(fmt, ..., domain=domain), width=width, exdent=2) paste(txt, collapse=\n) } stopf - function(..., call.=FALSE) { stop(.msg(...), call.=call.) } stopifnotf - function(test, fmt, ...) { if (!test) stopf(fmt, ...) } One might also wish to expose the condition class system, along the lines of .textf - ## a variant of .makeMessage function(fmt, ..., width = getOption(width), domain = NULL, appendLF = FALSE) { txt - gettextf(fmt, ..., domain = domain) msg - paste(strwrap(txt, width = width, indent = 2, exdent = 2), collapse=\n) if (appendLF) paste0(msg, \n) else msg } .condition - function(fmt, ..., class, call = NULL) { msg - .textf(fmt, ...) if (is.null(call)) msg - paste0(\n, msg) class - c(class, condition) structure(list(message=msg, call = call), class=class) } stopf - function(fmt, ..., class. = simpleError, call. = TRUE, domain = NULL) { call. - if (is.logical(call.) 1L == length(call.) call.) sys.call(-1) else NULL cond - .condition(fmt, ..., domain = domain, class = c(class., error), call = call.) stop(cond) } warnf - function(fmt, ..., class. = simpleWarning, call. = TRUE, domain = NULL) { ## does not support immediate., but options(warn=1) supported call. - if (is.logical(call.) 1L == length(call.) call.) sys.call(-1) else NULL cond - .condition(fmt, ..., domain = domain, class = c(class., warning ), call = call.) warning(cond) } messagef - function(fmt, ..., class. = simpleMessage, domain = NULL, appendLF = TRUE) { cond - .condition(fmt, ..., domain = domain, appendLF = appendLF, class = c(class., message)) message(cond) } -- Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel