Re: [R] automatically calling dev.off()
Yes, it's a different model, but maybe my main problem is that Rserve does not handle addTaskCallback as in the console (and thus no dev.off() is called). On Tue, Sep 1, 2015 at 5:00 PM, Duncan Murdoch wrote: > On 01/09/2015 10:13 AM, axionator wrote: > > Yes, the user could add something. Here, In about 90% of the time, he > > won't. So it would be nice to have a dev.off() as default (and some > > extra handling if more plot commands will follow). > > That's a different mental model of how graphics should work, and it's > not compatible with standard R graphics. However, it would be pretty > easy to get this to work with a grid graphics based systems (e.g. > ggplot2, lattice) since they don't draw anything until you print the > object: you'd just need to override the print method. > > Duncan Murdoch > > > > > > On Tue, Sep 1, 2015 at 4:04 PM, Duncan Murdoch > <mailto:murdoch.dun...@gmail.com>> wrote: > > > > On 01/09/2015 7:34 AM, axionator wrote: > > > Hi, > > > is there a way to automatically call dev.off()? > > > I use options(device="myfunc") to automatically open a device to > print to. > > > Afterwards, I would like to close it (so that the file is actually > written). > > > I tried to do it via addTaskCallback, but unfortunately, I have to > use > > > Rserve and (for any reason), the callback does not work (in the > default R > > > console on win7 it works, however). > > > > > > So, the following runs in the R console (but not via Rserve): > > > > > > mypng <- function(filename = "test.png", ...) > > > { > > > times <- function(total = 2, str = "Task") { > > > ctr <- 0 > > > function(expr, value, ok, visible) { > > > ctr <<- ctr + 1 > > > keep.me <http://keep.me> <- (ctr < total) > > > if (ctr == total) { > > > cat("ENDPRINT") > > > dev.off() > > > } > > > keep.me <http://keep.me> > > > } > > > } > > > png(filename, ...) > > > n <- addTaskCallback(times(1)) > > > } > > > options(device="mypng") > > > plot(rnorm(333)) > > > > > > > It wouldn't make sense to call dev.off() after the plot() command, > > because the user might be planning to add something to it. You need > to > > tell R that you are done, and that's what dev.off() is for. > > > > You can call it automatically in a function by using > > > > on.exit(dev.off()) > > > > and it should happen automatically at the end of an R session, but it > > *shouldn't* happen after every plotting call. > > > > Duncan Murdoch > > > > > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] automatically calling dev.off()
Yes, the user could add something. Here, In about 90% of the time, he won't. So it would be nice to have a dev.off() as default (and some extra handling if more plot commands will follow). On Tue, Sep 1, 2015 at 4:04 PM, Duncan Murdoch wrote: > On 01/09/2015 7:34 AM, axionator wrote: > > Hi, > > is there a way to automatically call dev.off()? > > I use options(device="myfunc") to automatically open a device to print > to. > > Afterwards, I would like to close it (so that the file is actually > written). > > I tried to do it via addTaskCallback, but unfortunately, I have to use > > Rserve and (for any reason), the callback does not work (in the default R > > console on win7 it works, however). > > > > So, the following runs in the R console (but not via Rserve): > > > > mypng <- function(filename = "test.png", ...) > > { > > times <- function(total = 2, str = "Task") { > > ctr <- 0 > > function(expr, value, ok, visible) { > > ctr <<- ctr + 1 > > keep.me <- (ctr < total) > > if (ctr == total) { > > cat("ENDPRINT") > > dev.off() > > } > > keep.me > > } > > } > > png(filename, ...) > > n <- addTaskCallback(times(1)) > > } > > options(device="mypng") > > plot(rnorm(333)) > > > > It wouldn't make sense to call dev.off() after the plot() command, > because the user might be planning to add something to it. You need to > tell R that you are done, and that's what dev.off() is for. > > You can call it automatically in a function by using > > on.exit(dev.off()) > > and it should happen automatically at the end of an R session, but it > *shouldn't* happen after every plotting call. > > Duncan Murdoch > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] automatically calling dev.off()
I did it on the console only for testing. I have a program that uses Rserve and would like to have it therefore. (the program basically provides a terminal where you can type in R commands. Since plotting is only possible via files (when using Rserve) that are then displayed in a widget, I like to avoid the overhead of writing png() ... dev.off() for each plot.) On Tue, Sep 1, 2015 at 3:42 PM, Jeff Newmiller wrote: > Don't use options to do this in batch mode. Open and close the file as you > make the plot. > --- > Jeff NewmillerThe . . Go Live... > DCN:Basics: ##.#. ##.#. Live > Go... > Live: OO#.. Dead: OO#.. Playing > Research Engineer (Solar/BatteriesO.O#. #.O#. with > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k > --- > Sent from my phone. Please excuse my brevity. > > On September 1, 2015 4:34:41 AM PDT, axionator > wrote: > >Hi, > >is there a way to automatically call dev.off()? > >I use options(device="myfunc") to automatically open a device to print > >to. > >Afterwards, I would like to close it (so that the file is actually > >written). > >I tried to do it via addTaskCallback, but unfortunately, I have to use > >Rserve and (for any reason), the callback does not work (in the default > >R > >console on win7 it works, however). > > > >So, the following runs in the R console (but not via Rserve): > > > >mypng <- function(filename = "test.png", ...) > >{ > >times <- function(total = 2, str = "Task") { > >ctr <- 0 > >function(expr, value, ok, visible) { > >ctr <<- ctr + 1 > >keep.me <- (ctr < total) > >if (ctr == total) { > >cat("ENDPRINT") > >dev.off() > >} > >keep.me > >} > >} > >png(filename, ...) > >n <- addTaskCallback(times(1)) > >} > >options(device="mypng") > >plot(rnorm(333)) > > > >Any hints? > > > > [[alternative HTML version deleted]] > > > >__ > >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > >https://stat.ethz.ch/mailman/listinfo/r-help > >PLEASE do read the posting guide > >http://www.R-project.org/posting-guide.html > >and provide commented, minimal, self-contained, reproducible code. > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] automatically calling dev.off()
Hi, is there a way to automatically call dev.off()? I use options(device="myfunc") to automatically open a device to print to. Afterwards, I would like to close it (so that the file is actually written). I tried to do it via addTaskCallback, but unfortunately, I have to use Rserve and (for any reason), the callback does not work (in the default R console on win7 it works, however). So, the following runs in the R console (but not via Rserve): mypng <- function(filename = "test.png", ...) { times <- function(total = 2, str = "Task") { ctr <- 0 function(expr, value, ok, visible) { ctr <<- ctr + 1 keep.me <- (ctr < total) if (ctr == total) { cat("ENDPRINT") dev.off() } keep.me } } png(filename, ...) n <- addTaskCallback(times(1)) } options(device="mypng") plot(rnorm(333)) Any hints? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] lbfgsb from C
Hi, I wanted to use R's lbfgsb method for minimization from C. Unfortunately, my toy examples always crashes (segmentation fault). What's wrong with it? double eval(int n, double* par, void *ex) { double result = 0; for (int i=0; ihttp://cran.r-project.org/doc/manuals/R-exts.html#Optimization void lbfgsb(int n, int lmm, double *x, double *lower, double *upper, int *nbd, double *Fmin, optimfn fn, optimgr gr, int *fail, void *ex, double factr, double pgtol, int *fncount, int *grcount, int maxit, char *msg, int trace, int nREPORT); */ lbfgsb(n, m, init, lower, upper, nbd, &Fmin, &eval, &grad, &fail, ex, factr, pgtol, &fncount, &grcount, maxit, msg, trace, nREPORT); printf("optimum at (%.2f,%.2f)\n", init[0], init[1]); return 0; } Thanks a lot. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] contour plot
That problem is that for every y I get a different x and thus cant create an array as in the help page examples. I was just wondering, whether there is a possibility to create such a contour plot easily without having to spend too much time with setting up a suitable matrix manually. Armin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] contour plot
Hi, I want to draw a contour plot of the following function: z = y*x + epsilon, where x ~ N(y, 1) and epsilon ~ N(0, sigma) with sigma fixed (e.g. 1) But didnt manage to feed "contour" with the right input. Thanks for your help. Armin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] counting entries in vector
rle(k)$lengths is perfectly suitable for my purposes. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] counting entries in vector
Hi all, I've a vector with entries, which are all of the same type, e.g. string: k <- c("bb", "bb", "bb", "aa", "cc", "cc") and want to create a second vector containing the number of each entry in k in the same order as in k, i.e. c(3, 1, 2) or: k <- c(5,5,5,5,2,2,4) => c(4,2,1) thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Simplex function in R
Hi, in the first example, your feasible set is just one point (the one that fulfills the 3 equations) and thus there is only this one point which can maximize the objective function. In the second case, the feasible set is a line. But the simplex algorithm tries to find an optimizing value of the objective on a convex polyhedron. So the simplex function may be inappropriate to find all feasible solutions. HTH Armin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Quantile Regression for longitudinal data
Hi all, does anybody know about R implementations for quantile regression for longitudinal data? I am just aware of a very basic version of R. Koenker's approach using fixed effects. Thanks in advance Armin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sampling from data.frame
sorry for being a little bit imprecise, Chuck interpreted my question as desired. Armin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] sampling from data.frame
Hi all, I have a data frame with "clustered" rows as follows: Cu1 x1 y1 z1 ... Cu1 x2 y2 z2 ... Cu1 x3 y3 z3 ... # end of first cluster Cu1 Cu2 x4 y4 z4 ... Cu2 x5 y5 z5 Cu2 ... # end of second cluster Cu2 Cu3 ... ... "cluster"-size is 3 in the example above (rows making up a cluster are always consecutive). Is there any faster way to sample n clusters (with replacement) from this dataframe and build up a new data frame out of these sampled clusters? I use the "sample" function and a for-loop. Thanks in advance Armin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] optimization problem
Hi, I guess your function has several local minima and depending on where you start, i.e. your initial variables, you get into another mimimum. HTH Armin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] construct a vector
Thanks, works fine. Armin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] construct a vector
Hi all, I have an unkown number of vectors (>=2) all of the same length. Out of these, I want to construct a new one as follows: having vectors u,v and w, the resulting vector z should have entries: z[1] = u[1], z[2] = v[1], z[3] = w[1] z[4] = u[2], z[5] = v[2], z[6] = w[2] ... i.e. go through the vector u,v,w, take at each time the 1st, 2sd, ... elements and store them consecutively in z. Is there an efficient way in R to do this? Thanks in advance Armin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.