Re: [Rd] Inferring dimensions on bitmap device from par()
On 1/25/07, Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > You asked > > > (or ultimately the dimension of the generated plot in pixels) without > > know which of png(), jpeg() or bitmap() was used? > > That is determined by arguments 'width' and 'height' in the call to the > device, and for the first two it is in pixels and for the third it is in > inches. Internally these are just numbers, and in particular the R > graphics system does not know the resolution to be used in pixelization. > Since some graphics parameters assume 'inches' and some 'pixels', > assumptions have to be made. png() assumes 96dpi and postscript() assumes > 72dpi. Thanks. That is useful to know. > > You had the information you asked for, so why not just use it? The function plotting does not know about the device, and I want to be able to keep fixed-sized margins in the output (assuming bitmap images). > R is not claiming to be your keeper. That is one of the answers I expected and wanted to hear given that it was the case. /Henrik > > On Thu, 25 Jan 2007, Henrik Bengtsson wrote: > > > Hi, > > > > I am trying to infer the dimension of an opened bitmap (png, jpeg, > > bitmap device...) from par() parmeters. From the help on par(), I > > found that: > > > >> dim <- c(400, 200) > >> png("foo.png", width=dim[1], height=dim[2]) > >> dim2 <- par("din") * par("cra") / par("cin") > >> dev.off() > >> dim2 > > [1] 399. 199. > > > > I've tried the above on Rv2.4.1 on WinXP and Linux with png() and > > jpeg() and the precision is good enough. However, when I turn to the > > bitmap() device, I found the following: > > > >> s <- 3; # Multiple of 72pt (default value of argument 'res' of bitmap()) > >> res <- s*72; > >> bitmap("foo.png", width=dim[1]/res, height=dim[2]/res, res=res) > >> dim2 <- par("din") * par("cra") / par("cin") > >> dev.off() > >> dim/dim2 > > [1] 3 3 > > > > That is, dim/dim2 is not one, but equal to the multiple 's'. I > > understand that this is because bitmap() is not a device per se and > > utilized postscript() plus a call to ghostscript. But still, does > > anyone know if it is possible to infer the correct resolution > > > > res2 <- s * par("cra") / par("cin") > > > > (or ultimately the dimension of the generated plot in pixels) without > > know which of png(), jpeg() or bitmap() was used? I know of > > par("ps"), but its "unit" is device specific. > > > > Thanks > > > > Henrik > > > > __ > > R-devel@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel > > > > -- > Brian D. Ripley, [EMAIL PROTECTED] > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UKFax: +44 1865 272595 > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] ?mean
G'day Gabor, On Thu, 25 Jan 2007 09:53:49 -0500 "Gabor Grothendieck" <[EMAIL PROTECTED]> wrote: > The help page for mean does not say what happens when one > applies mean to a matrix. Well, not directly. :-) But the help page of mean says that one of the arguments is: x: An R object. Currently there are methods for numeric data frames, numeric vectors and dates. A complex vector is allowed for 'trim = 0', only. And the `Value' section states: For a data frame, a named vector with the appropriate method being applied column by column. If 'trim' is zero (the default), the arithmetic mean of the values in 'x' is computed, as a numeric or complex vector of length one. If any argument is not logical (coerced to numeric), integer, numeric or complex, 'NA' is returned, with a warning. Since a matrix is a vector with a dimension attribute, and not a data frame, one can deduce that the second paragraph describes the return value for `mean(x)' when x is a matrix. As I always tell my students, reading R help pages is a bit of an art. :) > mean and sd work in an inconsistent way on a matrix so that should at > least be documented. Agreed. But it is documented in the help page of sd, which clearly states: [] If 'x' is a matrix or a data frame, a vector of the standard deviation of the columns is returned. I guess you also want to have it documented in the mean help page? But then, should `var' also be mentioned in the mean help page? This command also work in an a different and inconsistent manner to mean on matrices. And, of course, there are other subtle inconsistencies in the language used in these help pages. Note that the mean help page talks about "numeric data frames" while the help pages of `var' and `se' talk about "data frames" only, though all components of the data frame have to be numeric, of course. > Also there should be a See Also to colMeans since that provides the > missing column-wise analog to sd. That's probably a good idea. What would you suggest should be mentioned to provide the column-wise analog of `var'? Cheers, Berwin __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] i may have missed something ..
but deriv() and friends do not work in R-devel (at least not on the Mac). == Jan de Leeuw, 11667 Steinhoff Rd, Frazier Park, CA 93225 home 661-245-1725 skype 661-347-0667 global 254-381-4905 .mac: jdeleeuw +++ aim: deleeuwjan +++ skype: j_deleeuw == dodo2-1.pdf Description: Adobe PDF document __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] i may have missed something ..
On Thu, 25 Jan 2007, Jan de Leeuw wrote: > but deriv() and friends do not work in R-devel (at least > not on the Mac). They work for me under Linux and Windows. What does example(deriv) give you? > == > Jan de Leeuw, 11667 Steinhoff Rd, Frazier Park, CA 93225 > home 661-245-1725 skype 661-347-0667 global 254-381-4905 > .mac: jdeleeuw +++ aim: deleeuwjan +++ skype: j_deleeuw > == > -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Using Windows API functions in R
Somehow autofilter doesn't allow this message to be posted, will try another time. -Original Message- From: Yuri Volchik <[EMAIL PROTECTED]> To: r-devel@r-project.org Date: Thu, 25 Jan 2007 22:27:13 + Subject: Using Windows API functions in R > > Hi to all. > > In programming one application i have to "press" button to have > application started, which i would like to do automatically from R. > To do that i want to use library "user32" function "SendInput" > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/sendinput.asp > > So far i managed to write the following > > system(shQuote("C:/Program Files/1.exe"),wait=F) > system32 <- file.path(Sys.getenv("windir"),"system32") > user32 <- file.path(system32,"user32.dll") > dyn.load(user32) > .C("SendInput",..) > > And now i'm at loss how to represent the data structure needed for > correct call to that function, may be somebody could help me with > this? > > Thanks > > -- > Best regards, > Yuri mailto:[EMAIL PROTECTED] > > > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Using Windows API functions in R
On Fri, 26 Jan 2007, ? ??? wrote: > Somehow autofilter doesn't allow this message to be posted, > will try another time. > > -Original Message- > From: Yuri Volchik <[EMAIL PROTECTED]> > To: r-devel@r-project.org > Date: Thu, 25 Jan 2007 22:27:13 + > Subject: Using Windows API functions in R > >> >> Hi to all. >> >> In programming one application i have to "press" button to have >> application started, which i would like to do automatically from R. >> To do that i want to use library "user32" function "SendInput" >> >> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/sendinput.asp >> >> So far i managed to write the following >> >> system(shQuote("C:/Program Files/1.exe"),wait=F) >> system32 <- file.path(Sys.getenv("windir"),"system32") >> user32 <- file.path(system32,"user32.dll") >> dyn.load(user32) >> .C("SendInput",..) You cannot make use of WINAPI calls from .C (or otherwise in R): it is set up for _cdecl calls only. You will need to write some wrapper C code. >> And now i'm at loss how to represent the data structure needed for >> correct call to that function, may be somebody could help me with >> this? You cannot create C structures using .C, only a few basic array types. See ?".C" . Since you need wrapper code, you can create the structures needed there. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] double integral with C code
Hi all, This is more a C querie rather than a R one: I'm writing a C code passing a function F to adapt fortran subroutine. I need to integrate over two variables of F, call them x1 and x2. Then I call the C code in R to optimize the integrated F function. for example F could be defined as --- static double marg_like(const double *param, double x1, double x2){...} --- Then I integrate over x1 and x2 with - F77_CALL(adapt)(2,(-5,-5),(5,5),100,1700,F,0.01,1) - So here my question: I should I define x1 and x2? For the time being I defined them as static variables, i.e. static double x1; static double x2; but I'm pretty sure this is wrong Any hint? thanks in advance Stefano P.S. Sorry for having posted this in the R-help section, was an unintended mistake. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] readBin is much slower for raw input than for a file
Dear all, I'm trying to write an efficient binary file reader for a file type that is made up of several fields of variable length, and so requires many small reads. Doing this on the file directly using a sequence of readBin() calls is a bit too slow for my needs, so I tried buffering the file into a raw vector and reading from that ("loc" is the equivalent of the file pointer): fileSize <- file.info(fileName)$size connection <- file(fileName, "rb") bytes <- readBin(connection, "raw", n=fileSize) loc <- 0 close(connection) -- # within a custom read function: if (loc == 0) data <- readBin(bytes, what, n, size, ...) else if (loc > 0) data <- readBin(bytes[-(1:loc)], what, n, size, ...) However, this method runs almost 10 times slower for me than the sequence of file reads did. The initial call to readBin() - for reading in the file - is very quick, but running Rprof shows that the vast majority of the run time in doing the full parse is spent in readBin, so it does seem to be that that's slowing things down. Can anyone shed any light on why this is? I'm not expecting miracles here - and I realise that writing the whole read routine in C would be much quicker - but surely reading from a raw vector should work out faster than reading from a file? The system is R-2.4.1/Linux, Xeon 3.2 GHz, 2 GiB RAM; typical file size is 44 KiB. Thanks in advance, Jon __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Using Windows API functions in R
Thanks Professor, will try to create a wrapper needed to call WIN API functions. > > You cannot make use of WINAPI calls from .C (or otherwise in R): it is set > up for _cdecl calls only. > > You will need to write some wrapper C code. > > >> And now i'm at loss how to represent the data structure needed for > >> correct call to that function, may be somebody could help me with > >> this? > > You cannot create C structures using .C, only a few basic array types. > See ?".C" . Since you need wrapper code, you can create the structures > needed there. > > -- > Brian D. Ripley, [EMAIL PROTECTED] Best regards, Yuri Volchik __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] how to properly extend s3 data.frames with s4 classes?
Dear Ulf Martin, Thank you for your thoughtful analysis regarding the use of S3 data frames in S4. I asked the same question (in a more rudimentary manner) on the r-help list on 30 Nov 2006 and 04 Dec 2006. There were no replies. If you find a solution, please post. Best Regards, Tim Bergsma, PhD Date: Wed, 24 Jan 2007 12:28:46 +0100 From: Ulf Martin <[EMAIL PROTECTED]> Subject: [Rd] how to properly extend s3 data.frames with s4 classes? To: R-devel mailing list Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Dear R Programmers! After some time of using R I decided to work through John Chambers book "Programming with Data" to learn what these S4 classes are all about and how they work in R. (I regret not having picked up this rather fine book earlier!) I know from the documentation and the mailing archives that S4 in R is not 100% the book and that there are issues especially with dataframes, but to my knowledge the following has not been reported yet. Summary... __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Rscript on Windows
ActivePerl has '-x' switch which tells it to skip all lines in the file till "#!". This allows writing perl scripts in ordinary .bat files. ?shQuote contains a link with the following perl script example: ===8<=== @echo off :: hello.bat :: Windows executable Perl script :: Note: :: assumes perl.exe is in path :: otherwise, use absolute path perl -x -S "%0" %* goto end #!perl print "Hello, World!\n"; __END__ :end :: -- end of hello.bat -- Windows Notes: " -x " (lower case x): Skip all text until shebang line. " -S " (upper case S): Look for script using PATH variable. Special meaning in Windows: appends .bat or .cmd if lookup for name fails and name does not have either suffix. " %* " only on WinNT/2K/XP; use %1 %2 . . . %9 on Win9x/DOS ===8<=== I think the simplest way to implement shebang on windows would be embedding one more command line switch with similar functionality to perl's '-x'. -- View this message in context: http://www.nabble.com/Rscript-on-Windows-tf3120774.html#a8651815 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
Re: [Rd] Rscript on Windows
Good idea. ruby seems to work the same way. python does too but with a slightly different definition: C:\> ruby -h | findstr strip -x[directory] strip off text before #!ruby line and perhaps cd to directory C:\> perl -h | findstr strip -x[directory] strip off text before #!perl line and perhaps cd to directory C:\> python -h | findstr skip -x : skip first line of source, allowing use of non-Unix forms of #!cmd On 1/26/07, Vladimir Eremeev <[EMAIL PROTECTED]> wrote: > > ActivePerl has '-x' switch which tells it to skip all lines in the file till > "#!". > This allows writing perl scripts in ordinary .bat files. > > ?shQuote contains a link with the following perl script example: > ===8<=== > @echo off > :: hello.bat > :: Windows executable Perl script > :: Note: > :: assumes perl.exe is in path > :: otherwise, use absolute path > perl -x -S "%0" %* > goto end > #!perl > > print "Hello, World!\n"; > __END__ > :end > :: -- end of hello.bat -- > > Windows Notes: > " -x " (lower case x): Skip all text until shebang line. > " -S " (upper case S): Look for script using PATH variable. Special meaning > in Windows: appends .bat or .cmd if lookup for name fails and name does not > have either suffix. > " %* " only on WinNT/2K/XP; use %1 %2 . . . %9 on Win9x/DOS > ===8<=== > > I think the simplest way to implement shebang on windows would be embedding > one more command line switch with similar functionality to perl's '-x'. > > -- > View this message in context: > http://www.nabble.com/Rscript-on-Windows-tf3120774.html#a8651815 > 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 > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] i may have missed something ..
This is R revision 40576 compiled with icc/ifort on OS X 10.4.9 (8P2122). It may be the compiler. -- J. > example(deriv) deriv> ## formula argument : deriv> dx2x <- deriv(~ x^2, "x") ; dx2x expression({ .value <- x^2 .grad <- array(0, c(length(.value), 1), list(NULL, c("x"))) .grad[, "x"] <- 0 attr(.value, "gradient") <- .grad .value }) deriv> ## Not run: deriv> ##D expression({ deriv> ##D .value <- x^2 deriv> ##D .grad <- array(0, c(length(.value), 1), list (NULL, c("x"))) deriv> ##D .grad[, "x"] <- 2 * x deriv> ##D attr(.value, "gradient") <- .grad deriv> ##D .value deriv> ##D }) deriv> ## End(Not run) deriv> mode(dx2x) [1] "expression" deriv> x <- -1:2 deriv> eval(dx2x) [1] 1 0 1 4 attr(,"gradient") x [1,] 0 [2,] 0 [3,] 0 [4,] 0 deriv> ## Something 'tougher': deriv> trig.exp <- expression(sin(cos(x + y^2))) deriv> ( D.sc <- D(trig.exp, "x") ) [1] 0 deriv> all.equal(D(trig.exp[[1]], "x"), D.sc) [1] TRUE deriv> ( dxy <- deriv(trig.exp, c("x", "y")) ) expression({ .value <- sin(cos(x + y^2)) .grad <- array(0, c(length(.value), 2), list(NULL, c("x", "y"))) .grad[, "x"] <- 0 .grad[, "y"] <- 0 attr(.value, "gradient") <- .grad .value }) deriv> y <- 1 deriv> eval(dxy) [1] 0.8414710 0.5143953 -0.4042392 -0.8360219 attr(,"gradient") x y [1,] 0 0 [2,] 0 0 [3,] 0 0 [4,] 0 0 deriv> eval(D.sc) [1] 0 deriv> ## function returned: deriv> deriv((y ~ sin(cos(x) * y)), c("x","y"), func = TRUE) function (x, y) { .value <- sin(cos(x) * y) .grad <- array(0, c(length(.value), 2), list(NULL, c("x", "y"))) .grad[, "x"] <- 0 .grad[, "y"] <- 0 attr(.value, "gradient") <- .grad .value } deriv> ## function with defaulted arguments: deriv> (fx <- deriv(y ~ b0 + b1 * 2^(-x/th), c("b0", "b1", "th"), deriv+ function(b0, b1, th, x = 1:7){} ) ) function (b0, b1, th, x = 1:7) { .value <- b0 + b1 * 2^(-x/th) .grad <- array(0, c(length(.value), 3), list(NULL, c("b0", "b1", "th"))) .grad[, "b0"] <- 1 .grad[, "b1"] <- 0 .grad[, "th"] <- 0 attr(.value, "gradient") <- .grad .value } deriv> fx(2,3,4) [1] 4.522689 4.121320 3.783811 3.50 3.261345 3.060660 2.891905 attr(,"gradient") b0 b1 th [1,] 1 0 0 [2,] 1 0 0 [3,] 1 0 0 [4,] 1 0 0 [5,] 1 0 0 [6,] 1 0 0 [7,] 1 0 0 deriv> ## Higher derivatives deriv> deriv3(y ~ b0 + b1 * 2^(-x/th), c("b0", "b1", "th"), deriv+ c("b0", "b1", "th", "x") ) function (b0, b1, th, x) { .value <- b0 + b1 * 2^(-x/th) .grad <- array(0, c(length(.value), 3), list(NULL, c("b0", "b1", "th"))) .hessian <- array(0, c(length(.value), 3, 3), list(NULL, c("b0", "b1", "th"), c("b0", "b1", "th"))) .grad[, "b0"] <- 1 .grad[, "b1"] <- 0 .grad[, "th"] <- 0 attr(.value, "gradient") <- .grad attr(.value, "hessian") <- .hessian .value } deriv> ## Higher derivatives: deriv> DD <- function(expr,name, order = 1) { deriv+if(order < 1) stop("'order' must be >= 1") deriv+if(order == 1) D(expr,name) deriv+else DD(D(expr, name), name, order - 1) deriv+ } deriv> DD(expression(sin(x^2)), "x", 3) [1] 0 > On Jan 26, 2007, at 00:54 , Prof Brian Ripley wrote: > On Thu, 25 Jan 2007, Jan de Leeuw wrote: > >> but deriv() and friends do not work in R-devel (at least >> not on the Mac). > > They work for me under Linux and Windows. What does example(deriv) > give you? > >> == >> Jan de Leeuw, 11667 Steinhoff Rd, Frazier Park, CA 93225 >> home 661-245-1725 skype 661-347-0667 global 254-381-4905 >> .mac: jdeleeuw +++ aim: deleeuwjan +++ skype: j_deleeuw >> == >> > > -- > Brian D. Ripley, [EMAIL PROTECTED] > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UKFax: +44 1865 272595 == Jan de Leeuw, 11667 Steinhoff Rd, Frazier Park, CA 93225 home 661-245-1725 skype 661-347-0667 global 254-381-4905 .mac: jdeleeuw +++ aim: deleeuwjan +++ skype: j_deleeuw __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] i may have missed something ..
Ouch. It does look like a compiler over-optimization sort of problem. I presume that is the ix86 icc, with which we have not had much success on either Linux or Windows. I've just checked x86_64 icc on Linux, and that is working correctly. Brian On Fri, 26 Jan 2007, Jan de Leeuw wrote: > This is R revision 40576 compiled with icc/ifort > on OS X 10.4.9 (8P2122). It may be the compiler. > > -- J. > >> example(deriv) > > deriv> ## formula argument : > deriv> dx2x <- deriv(~ x^2, "x") ; dx2x > expression({ > .value <- x^2 > .grad <- array(0, c(length(.value), 1), list(NULL, c("x"))) > .grad[, "x"] <- 0 > attr(.value, "gradient") <- .grad > .value > }) > > deriv> ## Not run: > deriv> ##D expression({ > deriv> ##D .value <- x^2 > deriv> ##D .grad <- array(0, c(length(.value), 1), list(NULL, > c("x"))) > deriv> ##D .grad[, "x"] <- 2 * x > deriv> ##D attr(.value, "gradient") <- .grad > deriv> ##D .value > deriv> ##D }) > deriv> ## End(Not run) > deriv> mode(dx2x) > [1] "expression" > > deriv> x <- -1:2 > > deriv> eval(dx2x) > [1] 1 0 1 4 > attr(,"gradient") >x > [1,] 0 > [2,] 0 > [3,] 0 > [4,] 0 > > deriv> ## Something 'tougher': > deriv> trig.exp <- expression(sin(cos(x + y^2))) > > deriv> ( D.sc <- D(trig.exp, "x") ) > [1] 0 > > deriv> all.equal(D(trig.exp[[1]], "x"), D.sc) > [1] TRUE > > deriv> ( dxy <- deriv(trig.exp, c("x", "y")) ) > expression({ > .value <- sin(cos(x + y^2)) > .grad <- array(0, c(length(.value), 2), list(NULL, c("x", > "y"))) > .grad[, "x"] <- 0 > .grad[, "y"] <- 0 > attr(.value, "gradient") <- .grad > .value > }) > > deriv> y <- 1 > > deriv> eval(dxy) > [1] 0.8414710 0.5143953 -0.4042392 -0.8360219 > attr(,"gradient") >x y > [1,] 0 0 > [2,] 0 0 > [3,] 0 0 > [4,] 0 0 > > deriv> eval(D.sc) > [1] 0 > > deriv> ## function returned: > deriv> deriv((y ~ sin(cos(x) * y)), c("x","y"), func = TRUE) > function (x, y) > { > .value <- sin(cos(x) * y) > .grad <- array(0, c(length(.value), 2), list(NULL, c("x", > "y"))) > .grad[, "x"] <- 0 > .grad[, "y"] <- 0 > attr(.value, "gradient") <- .grad > .value > } > > deriv> ## function with defaulted arguments: > deriv> (fx <- deriv(y ~ b0 + b1 * 2^(-x/th), c("b0", "b1", "th"), > deriv+ function(b0, b1, th, x = 1:7){} ) ) > function (b0, b1, th, x = 1:7) > { > .value <- b0 + b1 * 2^(-x/th) > .grad <- array(0, c(length(.value), 3), list(NULL, c("b0", > "b1", "th"))) > .grad[, "b0"] <- 1 > .grad[, "b1"] <- 0 > .grad[, "th"] <- 0 > attr(.value, "gradient") <- .grad > .value > } > > deriv> fx(2,3,4) > [1] 4.522689 4.121320 3.783811 3.50 3.261345 3.060660 2.891905 > attr(,"gradient") >b0 b1 th > [1,] 1 0 0 > [2,] 1 0 0 > [3,] 1 0 0 > [4,] 1 0 0 > [5,] 1 0 0 > [6,] 1 0 0 > [7,] 1 0 0 > > deriv> ## Higher derivatives > deriv> deriv3(y ~ b0 + b1 * 2^(-x/th), c("b0", "b1", "th"), > deriv+ c("b0", "b1", "th", "x") ) > function (b0, b1, th, x) > { > .value <- b0 + b1 * 2^(-x/th) > .grad <- array(0, c(length(.value), 3), list(NULL, c("b0", > "b1", "th"))) > .hessian <- array(0, c(length(.value), 3, 3), list(NULL, > c("b0", "b1", "th"), c("b0", "b1", "th"))) > .grad[, "b0"] <- 1 > .grad[, "b1"] <- 0 > .grad[, "th"] <- 0 > attr(.value, "gradient") <- .grad > attr(.value, "hessian") <- .hessian > .value > } > > deriv> ## Higher derivatives: > deriv> DD <- function(expr,name, order = 1) { > deriv+if(order < 1) stop("'order' must be >= 1") > deriv+if(order == 1) D(expr,name) > deriv+else DD(D(expr, name), name, order - 1) > deriv+ } > > deriv> DD(expression(sin(x^2)), "x", 3) > [1] 0 >> > > On Jan 26, 2007, at 00:54 , Prof Brian Ripley wrote: > >> On Thu, 25 Jan 2007, Jan de Leeuw wrote: >> >>> but deriv() and friends do not work in R-devel (at least >>> not on the Mac). >> >> They work for me under Linux and Windows. What does example(deriv) give >> you? >> >>> == >>> Jan de Leeuw, 11667 Steinhoff Rd, Frazier Park, CA 93225 >>> home 661-245-1725 skype 661-347-0667 global 254-381-4905 >>> .mac: jdeleeuw +++ aim: deleeuwjan +++ skype: j_deleeuw >>> == >>> >> >> -- >> Brian D. Ripley, [EMAIL PROTECTED] >> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ >> University of Oxford, Tel: +44 1865 272861 (self) >> 1 South Parks Road, +44 1865 272866 (PA) >> Oxford OX1 3TG, UKFax: +44 1865 272595 > > == > Jan de Leeuw, 11667 Steinhoff Rd, Frazier Park, CA 93225 > home 661-245-1725 skype 661-347-0667 global 254-381-4905 > .mac: jdeleeuw +++ aim: deleeuwjan +++ skype: j_deleeuw > == > -- Brian D. Ripley, [EMAIL PROTECTED] Professor of App
[Rd] "[" operator and indexing ambiguity
Hi, I am working on writing some S4 classes that represent multidimensional (brain) image data. I would like these classes to support standard array indexing. I have been studying the Matrix and EBImage (http://www.bioconductor.org/packages/1.9/bioc/html/EBImage.html) packages to see how this is done. When using objects of the "array" class directly, R distinguishes between the calls: x[i,,] and x[i] with the former returning a 2D array of values and the latter returning a single value. The question I have is whether this same behavior can be simulated in classes that do not inherit from the "array" class directly? (See below for a snippet from the EBImage package which suggests that it cannot). My guess is that native array indexing is making use of the information provided by the commas, and this is unavailable to user implemented class methods? thanks, Brad Buchsbaum # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - setMethod("[", signature(x = "Image", i = "numeric", j = "missing"), function(x, i, j, k, ..., drop) { if (missing(k)) { warning("using index [int], cannot distinguish from [int,,ANY], use [int,1:dim(x)[2],ANY] otherwise") tmp = [EMAIL PROTECTED], drop = FALSE] } else { tmp = [EMAIL PROTECTED], , k, drop = FALSE] } ... } __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] i may have missed something ..
Yes. No such problem with the pair gcc/ifort. I'll try less aggressive optimization with icc on deriv.c (I also have to do that for regex.c). -- Jan On Jan 26, 2007, at 07:52 , Prof Brian Ripley wrote: > Ouch. It does look like a compiler over-optimization sort of problem. > > I presume that is the ix86 icc, with which we have not had much > success on either Linux or Windows. I've just checked x86_64 icc on > Linux, and that is working correctly. > > Brian > > == Jan de Leeuw, 11667 Steinhoff Rd, Frazier Park, CA 93225 home 661-245-1725 skype 661-347-0667 global 254-381-4905 .mac: jdeleeuw +++ aim: deleeuwjan +++ skype: j_deleeuw __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] i may have missed something ..
Switching the icc compiler flag from -O3 to -O0 for deriv.c solves the problem. As I said, I have to do that for regex.c as well. -- Jan On Jan 26, 2007, at 07:52 , Prof Brian Ripley wrote: > Ouch. It does look like a compiler over-optimization sort of problem. > > I presume that is the ix86 icc, with which we have not had much > success on either Linux or Windows. I've just checked x86_64 icc on > Linux, and that is working correctly. > > Brian > > == Jan de Leeuw, 11667 Steinhoff Rd, Frazier Park, CA 93225 home 661-245-1725 skype 661-347-0667 global 254-381-4905 .mac: jdeleeuw +++ aim: deleeuwjan +++ skype: j_deleeuw __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] "[" operator and indexing ambiguity
Hackish (and maybe expensive; does match.call duplicate the call arguments?), but maybe setClass("A", "numeric") setMethod("[", c(x="A"), function(x, i, j, ..., drop=TRUE) { "..." %in% names(match.call(expand.dots=FALSE)) }) > a <- new("A") > a[i] [1] FALSE > a[i,,] [1] TRUE ? Martin "Bradley Buchsbaum" <[EMAIL PROTECTED]> writes: > Hi, > > I am working on writing some S4 classes that represent > multidimensional (brain) image data. I would like these classes to > support standard array indexing. I have been studying the Matrix and > EBImage (http://www.bioconductor.org/packages/1.9/bioc/html/EBImage.html) > packages to see how this is done. > > When using objects of the "array" class directly, R distinguishes > between the calls: > > x[i,,] and x[i] > > with the former returning a 2D array of values and the latter > returning a single value. The question I have is whether this same > behavior can be simulated in classes that do not inherit from the > "array" class directly? (See below for a snippet from the EBImage > package which suggests that it cannot). > > My guess is that native array indexing is making use of the > information provided by the commas, and this is unavailable to user > implemented class methods? > > thanks, > > Brad Buchsbaum > > > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > setMethod("[", signature(x = "Image", i = "numeric", j = "missing"), > function(x, i, j, k, ..., drop) { > if (missing(k)) { > warning("using index [int], cannot distinguish from > [int,,ANY], use [int,1:dim(x)[2],ANY] otherwise") > tmp = [EMAIL PROTECTED], drop = FALSE] > } > else { > tmp = [EMAIL PROTECTED], , k, drop = FALSE] > } > ... > } > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel -- Martin Morgan Bioconductor / Computational Biology http://bioconductor.org __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] FW: reducing RODBC odbcQuery memory use?
New to R, sorry if one or either of these is an inappropriate list for a question like this below; please let me know if this is a general help question. Jill Willie Open Seas Safeco Insurance [EMAIL PROTECTED] -Original Message- From: WILLIE, JILL Sent: Thursday, January 25, 2007 2:27 PM To: r-help@stat.math.ethz.ch Subject: reducing RODBC odbcQuery memory use? Basic Questions: 1. Can I avoid having RODBC use so much memory (35 times the data size or more) making a data.frame & then .rda file via. sqlQuery/save? 2. If not, is there some more appropriate way from w/in R to pull large data sets (2-5GB) into .rda files from sql? Testing details (R transcript below): 1GB CPU, 1GB RAM windows machine. 1. testing bigger input table (AUTCombinedWA_BILossCost_1per), size is 20MB in sql, 10 rows, 2 numeric columns, 55 integer columns; consumes 35kb of memory & 80kb of virtual memory to execute the sqlQuery command. Memory not released after the step finishes or upon execution of odbcCloseAll(), or gc(). 2. tested small input table, size is 2MB in sql, 1 rows, 2 numeric columns, 55 integer columns; consumes 55000kb of memory & 515000kb (vm seems oddly high to me) of virtual memory to execute the sqlQuery command. 3. concluded the high memory use is isolated to the odbcQuery step w/in the sqlQuery function as opposed to sqlGetResults or ODBC itself. Relevant R session transcript: >library(RODBC) >channel<-odbcConnect("psmrd") >df_OnePer <-data.frame(sqlQuery(channel, "select * from AUTCombinedWA_BILossCost_1per")) >save(df_OnePer, file = "df_OnePer.rda") Additional testing details: I exited R which released all memory cleanly, then started R again, loaded the .rda saved in prior step as below. This confirmed relatively little of the memory is consumed going from .rda to data frame; isolating to the RODBC step: > load("df_OnePer.rda") > df <- data.frame(df_OnePer) I closed R & opened MS Access & used the same DSN "psmrd", & to import the AUTCombinedWA_BILossCost_1per into MS Access which required about 3kb of memory & 2kb of virtual. And finally, I have this excerpt from Prof Brian Ripley that seems potentially relevant (if it's not just confusion because I called them 'byte-size' when really I should have said they're integers just having values limited to 1-255). In any case I'm unable to see from the RODBC help how to specify this: "...sqlQuery returns a data frame directly. I think you need to tell RODBC to translate your 'byte-sized factors' to numeric, as it will be going through character if these are a type it does not know about." Read all the RODBC help, read all the data import guide & searched help archives...can't find an answer. Would appreciate advice, experience, or direction. Jill Willie Open Seas Safeco Insurance [EMAIL PROTECTED] -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Thursday, January 25, 2007 12:05 AM To: WILLIE, JILL Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Size of data vs. needed memory...rule of thumb? On Wed, 24 Jan 2007, WILLIE, JILL wrote: > I have been searching all day & most of last night, but can't find any > benchmarking or recommendations regarding R system requirements for very > large (2-5GB) data sets to help guide our hardware configuration. If > anybody has experience with this they're willing to share or could > anybody point me in a direction that might be productive to research, it > would be much appreciated. Specifically: will R simply use as much > memory as the OS makes available to it, unlimited? Under most OSes. Because Windows has no means to limit the amount made available, R under Windows does have it own limiting mechanism (which you hit in the examples below). R under Linux will allow you to run a 4GB process on a machine with 2GB RAM, but you are likely to get around 0.7% usage. (One of my colleagues did that on a server earlier this week, hence the very specific answer.) > Is there a multi-threading version R, packages? Not to run computations in R. Some parts of R (e.g. GUIs) and some libraries (e.g. some BLAS) are multithreaded. There are multiprocess packages, e.g. Rmpi, rpvm, snow. > Does the core R package support 64-bit Yes, and has for many years. > & should I expect to see any difference in how memory's handled under > that version? yes, because the address space will not get seriously fragmented. See the appropriate section in R-admin.html (referenced from INSTALL). > Is 3 GB of memory to 1GB of data a reasonable ballpark? I'd say it was a bit low, but it really depends on the analysis you are doing, how 1GB of data is made up (many rows?, many cols?, etc) and so on. Had you asked me to suggest a ratio I would have said 5. > Our testing thus far has been on a windows 32-bit box w/1GB of RAM & 1 > CPU; it appears to indicate something like 3GB of RAM for every 1GB of > sql table (ex-indexes, byte-sized fa
Re: [Rd] "[" operator and indexing ambiguity
You can find this info using the function nargs(). I've used this with S3 classes, and as far as I know it should work with S4 classes too. See ?nargs for examples. -- Tony Plate Bradley Buchsbaum wrote: > Hi, > > I am working on writing some S4 classes that represent > multidimensional (brain) image data. I would like these classes to > support standard array indexing. I have been studying the Matrix and > EBImage (http://www.bioconductor.org/packages/1.9/bioc/html/EBImage.html) > packages to see how this is done. > > When using objects of the "array" class directly, R distinguishes > between the calls: > > x[i,,] and x[i] > > with the former returning a 2D array of values and the latter > returning a single value. The question I have is whether this same > behavior can be simulated in classes that do not inherit from the > "array" class directly? (See below for a snippet from the EBImage > package which suggests that it cannot). > > My guess is that native array indexing is making use of the > information provided by the commas, and this is unavailable to user > implemented class methods? > > thanks, > > Brad Buchsbaum > > > > # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - > setMethod("[", signature(x = "Image", i = "numeric", j = "missing"), > function(x, i, j, k, ..., drop) { > if (missing(k)) { > warning("using index [int], cannot distinguish from > [int,,ANY], use [int,1:dim(x)[2],ANY] otherwise") > tmp = [EMAIL PROTECTED], drop = FALSE] > } > else { > tmp = [EMAIL PROTECTED], , k, drop = FALSE] > } > ... > } > > __ > 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] Error in loadNamespace(name) (PR#9464)
Thank you for your reply. There is some more information that may help your reproduce the error. The .RData file was generated under MSWindows. I started with an empty workspace and generated an object by y <- runif(200) or very similar. the quit, saving the workspace. (NTFS partition) I then logged out of Windows, logged into Lunix (Ubuntu Edgy Eft), cd'ed to where the .RData file lived and tried to start R. I have had the same experience with larger (real) workspaces. If I remove the .RData file there is no problem. Regards Ross Darnell Prof Brian Ripley wrote: > There is nothing here to reproduce. > It clearly depends on your .RData, which is not available to us. > Unless you can make it available, we cannot help. > > On Thu, 25 Jan 2007, [EMAIL PROTECTED] wrote: > >> Full_Name: Ross Darnell >> Version: 2.4.1 >> OS: Linux >> Submission from: (NULL) (130.102.133.33) >> >> >> [EMAIL PROTECTED]:~/Data$ ls -al .RData >> -rwxrwxrwx 2 root root 13551 2006-12-06 08:58 .RData >> [EMAIL PROTECTED]:~/Data$ R >> >> R version 2.4.1 (2006-12-18) >> Copyright (C) 2006 The R Foundation for Statistical Computing >> ISBN 3-900051-07-0 >> >> R is free software and comes with ABSOLUTELY NO WARRANTY. >> You are welcome to redistribute it under certain conditions. >> Type 'license()' or 'licence()' for distribution details. >> >> Natural language support but running in an English locale >> >> R is a collaborative project with many contributors. >> Type 'contributors()' for more information and >> 'citation()' on how to cite R or R packages in publications. >> >> Type 'demo()' for some demos, 'help()' for on-line help, or >> 'help.start()' for an HTML browser interface to help. >> Type 'q()' to quit R. >> >> Error in loadNamespace(name) : there is no package called 'lattice' >> Fatal error: unable to restore saved data in .RData >> >> [EMAIL PROTECTED]:~/Data$ R --no-restore-data >> >>> load(".RData") >> Error in loadNamespace(name) : there is no package called 'lattice' >> >> >> >> --please do not edit the information below-- >> >> Version: >> platform = i486-pc-linux-gnu >> arch = i486 >> os = linux-gnu >> system = i486, linux-gnu >> status = >> major = 2 >> minor = 4.1 >> year = 2006 >> month = 12 >> day = 18 >> svn rev = 40228 >> language = R >> version.string = R version 2.4.1 (2006-12-18) >> >> Locale: >> LC_CTYPE=en_AU.UTF-8;LC_NUMERIC=C;LC_TIME=en_AU.UTF-8;LC_COLLATE=en_AU.UTF-8;LC_MONETARY=en_AU.UTF-8;LC_MESSAGES=en_AU.UTF-8;LC_PAPER=en_AU.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_AU.UTF-8;LC_IDENTIFICATION=C >> >> >> >> Search Path: >> .GlobalEnv, package:stats, package:graphics, package:grDevices, >> package:utils, >> package:datasets, package:methods, Autoloads, package:base >> >> __ >> 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