[R] Release of rclipboard 0.2.0
Hi, Version 0.2.0 of rclipboard has been released to CRAN. This provides a minor update of the underlying js library and a support for display of `bslib::tooltip` for Shiny apps built with `bslib` package. Enjoy! [[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] Nonlinear logistic regression fitting
Thanks Duncan, (Sorry for the repeated email) People working in my field are frequently (and rightly) accused of butchering statistical terminology. So I guess I'm guilty as charged I will look into the suggested path. One question though in your expression of loglik, p is "a + b*x/(c+x)". Correct? Thanks From: Duncan Murdoch Sent: Wednesday, July 29, 2020 16:04 To: Sebastien Bihorel ; J C Nash ; r-help@r-project.org Subject: Re: [R] Nonlinear logistic regression fitting Just a quick note about jargon: you are using the word "likelihood" in a way that I (and maybe some others) find confusing. (In fact, I think you used it two different ways, but maybe I'm just confused.) I would say that likelihood is the probability of observing the entire data set, considered as a function of the parameters. You appear to be using it (at first) as the probability that a particular observation is equal to 1, and then as the argument to a logit function to give that probability. What you probably want to do is find the parameters that maximize the likelihood (in my sense). The usual practice is to maximize the log of the likelihood; it tends to be easier to work with. In your notation below, the log likelihood would be loglik <- sum( resp*log(p) + (1-resp)*log1p(-p) ) When you have a linear logistic regression model, this simplifies a bit, and there are fast algorithms that are usually stable to optimize it. With a nonlinear model, you lose some of that, and I'd suggest directly optimizing it. Duncan Murdoch On 29/07/2020 8:56 a.m., Sebastien Bihorel via R-help wrote: > Thank your, Pr. Nash, for your perspective on the issue. > > Here is an example of binary data/response (resp) that were simulated and > re-estimated assuming a non linear effect of the predictor (x) on the > likelihood of response. For re-estimation, I have used gnlm::bnlr for the > logistic regression. The accuracy of the parameter estimates is so-so, > probably due to the low number of data points (8*nx). For illustration, I > have also include a glm call to an incorrect linear model of x. > > #install.packages(gnlm) > #require(gnlm) > set.seed(12345) > > nx <- 10 > x <- c( >rep(0, 3*nx), >rep(c(10, 30, 100, 500, 1000), each = nx) > ) > rnd <- runif(length(x)) > a <- log(0.2/(1-0.2)) > b <- log(0.7/(1-0.7)) - a > c <- 30 > likelihood <- a + b*x/(c+x) > p <- exp(likelihood) / (1 + exp(likelihood)) > resp <- ifelse(rnd <= p, 1, 0) > > df <- data.frame( >x = x, >resp = resp, >nresp = 1- resp > ) > > head(df) > > # glm can only assume linear effect of x, which is the wrong model > glm_mod <- glm( >resp~x, >data = df, >family = 'binomial' > ) > glm_mod > > # Using gnlm package, estimate a model model with just intercept, and a model > with predictor effect > int_mod <- gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a, pmu = c(a) ) > emax_mod <- gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a + > p_b*x/(p_c+x), pmu = c(a, b, c) ) > > int_mod > emax_mod > > > From: J C Nash > Sent: Tuesday, July 28, 2020 14:16 > To: Sebastien Bihorel ; > r-help@r-project.org > Subject: Re: [R] Nonlinear logistic regression fitting > > There is a large literature on nonlinear logistic models and similar > curves. Some of it is referenced in my 2014 book Nonlinear Parameter > Optimization Using R Tools, which mentions nlxb(), now part of the > nlsr package. If useful, I could put the Bibtex refs for that somewhere. > > nls() is now getting long in the tooth. It has a lot of flexibility and > great functionality, but it did very poorly on the Hobbs problem that > rather forced me to develop the codes that are 3/5ths of optim() and > also led to nlsr etc. The Hobbs problem dated from 1974, and with only > 12 data points still defeats a majority of nonlinear fit programs. > nls() poops out because it has no LM stabilization and a rather weak > forward difference derivative approximation. nlsr tries to generate > analytic derivatives, which often help when things are very badly scaled. > > Another posting suggests an example problem i.e., some data and a > model, though you also need the loss function (e.g., Max likelihood, > weights, etc.). Do post some data and functions so we can provide more > focussed advice. > > JN > > On 2020-07-28 10:13 a.m., Sebastien Bihorel via R-help wrote: >> Hi >> >> I need to fit a logistic regression model using a saturable Michaelis-Menten >> function of my predictor x. The likelihood could be expressed as: >> >> L = intercept + emax * x / (EC50+x) >> >> Whi
Re: [R] Nonlinear logistic regression fitting
Thanks Duncan, People working in my field are frequently (and rightly) accused of butchering statistical terminology. So I guess I'm guilty as charged I will look into the suggested path. One question though in your expression: loglik <- sum( resp*log(p) + (1-resp)*log1p(-p) ) a + b*x/(c+x) From: Duncan Murdoch Sent: Wednesday, July 29, 2020 16:04 To: Sebastien Bihorel ; J C Nash ; r-help@r-project.org Subject: Re: [R] Nonlinear logistic regression fitting Just a quick note about jargon: you are using the word "likelihood" in a way that I (and maybe some others) find confusing. (In fact, I think you used it two different ways, but maybe I'm just confused.) I would say that likelihood is the probability of observing the entire data set, considered as a function of the parameters. You appear to be using it (at first) as the probability that a particular observation is equal to 1, and then as the argument to a logit function to give that probability. What you probably want to do is find the parameters that maximize the likelihood (in my sense). The usual practice is to maximize the log of the likelihood; it tends to be easier to work with. In your notation below, the log likelihood would be loglik <- sum( resp*log(p) + (1-resp)*log1p(-p) ) When you have a linear logistic regression model, this simplifies a bit, and there are fast algorithms that are usually stable to optimize it. With a nonlinear model, you lose some of that, and I'd suggest directly optimizing it. Duncan Murdoch On 29/07/2020 8:56 a.m., Sebastien Bihorel via R-help wrote: > Thank your, Pr. Nash, for your perspective on the issue. > > Here is an example of binary data/response (resp) that were simulated and > re-estimated assuming a non linear effect of the predictor (x) on the > likelihood of response. For re-estimation, I have used gnlm::bnlr for the > logistic regression. The accuracy of the parameter estimates is so-so, > probably due to the low number of data points (8*nx). For illustration, I > have also include a glm call to an incorrect linear model of x. > > #install.packages(gnlm) > #require(gnlm) > set.seed(12345) > > nx <- 10 > x <- c( >rep(0, 3*nx), >rep(c(10, 30, 100, 500, 1000), each = nx) > ) > rnd <- runif(length(x)) > a <- log(0.2/(1-0.2)) > b <- log(0.7/(1-0.7)) - a > c <- 30 > likelihood <- a + b*x/(c+x) > p <- exp(likelihood) / (1 + exp(likelihood)) > resp <- ifelse(rnd <= p, 1, 0) > > df <- data.frame( >x = x, >resp = resp, >nresp = 1- resp > ) > > head(df) > > # glm can only assume linear effect of x, which is the wrong model > glm_mod <- glm( >resp~x, >data = df, >family = 'binomial' > ) > glm_mod > > # Using gnlm package, estimate a model model with just intercept, and a model > with predictor effect > int_mod <- gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a, pmu = c(a) ) > emax_mod <- gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a + > p_b*x/(p_c+x), pmu = c(a, b, c) ) > > int_mod > emax_mod > > > From: J C Nash > Sent: Tuesday, July 28, 2020 14:16 > To: Sebastien Bihorel ; > r-help@r-project.org > Subject: Re: [R] Nonlinear logistic regression fitting > > There is a large literature on nonlinear logistic models and similar > curves. Some of it is referenced in my 2014 book Nonlinear Parameter > Optimization Using R Tools, which mentions nlxb(), now part of the > nlsr package. If useful, I could put the Bibtex refs for that somewhere. > > nls() is now getting long in the tooth. It has a lot of flexibility and > great functionality, but it did very poorly on the Hobbs problem that > rather forced me to develop the codes that are 3/5ths of optim() and > also led to nlsr etc. The Hobbs problem dated from 1974, and with only > 12 data points still defeats a majority of nonlinear fit programs. > nls() poops out because it has no LM stabilization and a rather weak > forward difference derivative approximation. nlsr tries to generate > analytic derivatives, which often help when things are very badly scaled. > > Another posting suggests an example problem i.e., some data and a > model, though you also need the loss function (e.g., Max likelihood, > weights, etc.). Do post some data and functions so we can provide more > focussed advice. > > JN > > On 2020-07-28 10:13 a.m., Sebastien Bihorel via R-help wrote: >> Hi >> >> I need to fit a logistic regression model using a saturable Michaelis-Menten >> function of my predictor x. The likelihood could be expressed as: >> >> L = intercept + emax * x / (EC50+x) >> >> Which I guess could be express
Re: [R] Nonlinear logistic regression fitting
Thank your, Pr. Nash, for your perspective on the issue. Here is an example of binary data/response (resp) that were simulated and re-estimated assuming a non linear effect of the predictor (x) on the likelihood of response. For re-estimation, I have used gnlm::bnlr for the logistic regression. The accuracy of the parameter estimates is so-so, probably due to the low number of data points (8*nx). For illustration, I have also include a glm call to an incorrect linear model of x. #install.packages(gnlm) #require(gnlm) set.seed(12345) nx <- 10 x <- c( rep(0, 3*nx), rep(c(10, 30, 100, 500, 1000), each = nx) ) rnd <- runif(length(x)) a <- log(0.2/(1-0.2)) b <- log(0.7/(1-0.7)) - a c <- 30 likelihood <- a + b*x/(c+x) p <- exp(likelihood) / (1 + exp(likelihood)) resp <- ifelse(rnd <= p, 1, 0) df <- data.frame( x = x, resp = resp, nresp = 1- resp ) head(df) # glm can only assume linear effect of x, which is the wrong model glm_mod <- glm( resp~x, data = df, family = 'binomial' ) glm_mod # Using gnlm package, estimate a model model with just intercept, and a model with predictor effect int_mod <- gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a, pmu = c(a) ) emax_mod <- gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a + p_b*x/(p_c+x), pmu = c(a, b, c) ) int_mod emax_mod From: J C Nash Sent: Tuesday, July 28, 2020 14:16 To: Sebastien Bihorel ; r-help@r-project.org Subject: Re: [R] Nonlinear logistic regression fitting There is a large literature on nonlinear logistic models and similar curves. Some of it is referenced in my 2014 book Nonlinear Parameter Optimization Using R Tools, which mentions nlxb(), now part of the nlsr package. If useful, I could put the Bibtex refs for that somewhere. nls() is now getting long in the tooth. It has a lot of flexibility and great functionality, but it did very poorly on the Hobbs problem that rather forced me to develop the codes that are 3/5ths of optim() and also led to nlsr etc. The Hobbs problem dated from 1974, and with only 12 data points still defeats a majority of nonlinear fit programs. nls() poops out because it has no LM stabilization and a rather weak forward difference derivative approximation. nlsr tries to generate analytic derivatives, which often help when things are very badly scaled. Another posting suggests an example problem i.e., some data and a model, though you also need the loss function (e.g., Max likelihood, weights, etc.). Do post some data and functions so we can provide more focussed advice. JN On 2020-07-28 10:13 a.m., Sebastien Bihorel via R-help wrote: > Hi > > I need to fit a logistic regression model using a saturable Michaelis-Menten > function of my predictor x. The likelihood could be expressed as: > > L = intercept + emax * x / (EC50+x) > > Which I guess could be expressed as the following R model > > ~ emax*x/(ec50+x) > > As far as I know (please, correct me if I am wrong), fitting such a model is > to not doable with glm, since the function is not linear. > > A Stackoverflow post recommends the bnlr function from the gnlm > (https://stackoverflow.com/questions/45362548/nonlinear-logistic-regression-package-in-r)... > I would be grateful for any opinion on this package or for any alternative > recommendation of package/function. > __ > 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.
Re: [R] Nonlinear logistic regression fitting
Hi Rui, Thanks for your input. In my analysis, the MM model is not intended to fit continuous data but must be used within a logistic regression model of binary data. So, while useful in itself, the suggested example does not exactly apply. I appreciate your time From: Rui Barradas Sent: Tuesday, July 28, 2020 12:42 To: Sebastien Bihorel ; r-help@r-project.org Subject: Re: [R] Nonlinear logistic regression fitting Hello, glm might not be the right tool for the MM model but nls is meant to fit non-linear models. And, after an on-line search, there is also package drc, function drm. I will use the data and examples in the links below. (The second gave me right, it uses nls.) #install.packages("drc") library(drc) #--- data # substrate S <- c(0,1,2,5,8,12,30,50) # reaction rate v <- c(0,11.1,25.4,44.8,54.5,58.2,72.0,60.1) kinData <- data.frame(S, v) #--- package drc fit # use the two parameter MM model (MM.2) drm_fit <- drm(v ~ S, data = kinData, fct = MM.2()) #--- nls fit MMcurve <- formula(v ~ Vmax*S/(Km + S)) nls_fit <- nls(MMcurve, kinData, start = list(Vmax = 50, Km = 2)) coef(drm_fit) coef(nls_fit) #--- plot SconcRange <- seq(0, 50, 0.1) nls_Line <- predict(nls_fit, list(S = SconcRange)) plot(drm_fit, log = '', pch = 17, col = "red", main = "Fitted MM curve") lines(SconcRange, nls_Line, col = "blue", lty = "dotted") [1] https://davetang.org/muse/2013/05/17/fitting-a-michaelis-mentens-curve-using/ [2] http://rforbiochemists.blogspot.com/2015/05/plotting-and-fitting-enzymology-data.html Hope this helps, Rui Barradas �s 15:13 de 28/07/2020, Sebastien Bihorel via R-help escreveu: > Hi > > I need to fit a logistic regression model using a saturable Michaelis-Menten > function of my predictor x. The likelihood could be expressed as: > > L = intercept + emax * x / (EC50+x) > > Which I guess could be expressed as the following R model > > ~ emax*x/(ec50+x) > > As far as I know (please, correct me if I am wrong), fitting such a model is > to not doable with glm, since the function is not linear. > > A Stackoverflow post recommends the bnlr function from the gnlm > (https://stackoverflow.com/questions/45362548/nonlinear-logistic-regression-package-in-r)... > I would be grateful for any opinion on this package or for any alternative > recommendation of package/function. > __ > 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. -- Este e-mail foi verificado em termos de v�rus pelo software antiv�rus Avast. https://www.avast.com/antivirus [[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] Nonlinear logistic regression fitting
I hardly see how your reply addressed my question or any part of it. It looks to me that it was simply assumed that I did not perform any search before posting. From: Bert Gunter Sent: Tuesday, July 28, 2020 11:30 To: Sebastien Bihorel Cc: r-help@r-project.org Subject: Re: [R] Nonlinear logistic regression fitting You said: "As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear." My reply responded to that. AFAIK, opinions on packages are off topic here. Try stats.stackexchange.com<http://stats.stackexchange.com> for that. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Jul 28, 2020 at 8:19 AM Sebastien Bihorel mailto:sebastien.biho...@cognigencorp.com>> wrote: Thank you for your subtle input, Bert... as usual! This is literally the search I conducted and spent 2 hours on before posting to R-help. I was asking for expert opinions, not for search engine FAQ! Thank anyways From: Bert Gunter mailto:bgunter.4...@gmail.com>> Sent: Tuesday, July 28, 2020 11:12 To: Sebastien Bihorel mailto:sebastien.biho...@cognigencorp.com>> Cc: r-help@r-project.org<mailto:r-help@r-project.org> mailto:r-help@r-project.org>> Subject: Re: [R] Nonlinear logistic regression fitting Search! ... for "nonlinear logistic regression" at rseek.org<http://rseek.org>. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Jul 28, 2020 at 7:25 AM Sebastien Bihorel via R-help mailto:r-help@r-project.org>> wrote: Hi I need to fit a logistic regression model using a saturable Michaelis-Menten function of my predictor x. The likelihood could be expressed as: L = intercept + emax * x / (EC50+x) Which I guess could be expressed as the following R model ~ emax*x/(ec50+x) As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear. A Stackoverflow post recommends the bnlr function from the gnlm (https://stackoverflow.com/questions/45362548/nonlinear-logistic-regression-package-in-r)... I would be grateful for any opinion on this package or for any alternative recommendation of package/function. __ R-help@r-project.org<mailto: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.
Re: [R] Nonlinear logistic regression fitting
Thank you for your subtle input, Bert... as usual! This is literally the search I conducted and spent 2 hours on before posting to R-help. I was asking for expert opinions, not for search engine FAQ! Thank anyways From: Bert Gunter Sent: Tuesday, July 28, 2020 11:12 To: Sebastien Bihorel Cc: r-help@r-project.org Subject: Re: [R] Nonlinear logistic regression fitting Search! ... for "nonlinear logistic regression" at rseek.org<http://rseek.org>. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Jul 28, 2020 at 7:25 AM Sebastien Bihorel via R-help mailto:r-help@r-project.org>> wrote: Hi I need to fit a logistic regression model using a saturable Michaelis-Menten function of my predictor x. The likelihood could be expressed as: L = intercept + emax * x / (EC50+x) Which I guess could be expressed as the following R model ~ emax*x/(ec50+x) As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear. A Stackoverflow post recommends the bnlr function from the gnlm (https://stackoverflow.com/questions/45362548/nonlinear-logistic-regression-package-in-r)... I would be grateful for any opinion on this package or for any alternative recommendation of package/function. __ R-help@r-project.org<mailto: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] Nonlinear logistic regression fitting
Hi I need to fit a logistic regression model using a saturable Michaelis-Menten function of my predictor x. The likelihood could be expressed as: L = intercept + emax * x / (EC50+x) Which I guess could be expressed as the following R model ~ emax*x/(ec50+x) As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear. A Stackoverflow post recommends the bnlr function from the gnlm (https://stackoverflow.com/questions/45362548/nonlinear-logistic-regression-package-in-r)... I would be grateful for any opinion on this package or for any alternative recommendation of package/function. __ 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] Creating file from raw connection
Thanks Duncan From: Duncan Murdoch Sent: Friday, May 29, 2020 15:36 To: Sebastien Bihorel ; r-help@r-project.org Subject: Re: [R] Creating file from raw connection On 29/05/2020 3:00 p.m., Sebastien Bihorel via R-help wrote: > Hi, > > Let's say I can extract the content of an Excel .xlsx file stored in a > database and store it as raw content in an R object. What would be the proper > way to "create" a .xlsx file and "transfer" the content of this obj into it? > I took the example of an Excel file, but my question would extend to any kind > of binary file. > > Thank you in advance for your input It depends on how the .xlsx was put in to the database and then extracted into R, but if it's just a copy of a file from disk, writeBin() will write it without changes. Duncan Murdoch __ 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] Creating file from raw content
Hi, Let's say I can extract the content of an Excel .xlsx file stored in a database and store it as raw content in an R object. What would be the proper way to "create" a .xlsx file and "transfer" the content of this obj into it? I took the example of an Excel file, but my question would extend to any kind of binary file. Thank you in advance for your input Sebastien __ 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] Creating file from raw connection
Hi, Let's say I can extract the content of an Excel .xlsx file stored in a database and store it as raw content in an R object. What would be the proper way to "create" a .xlsx file and "transfer" the content of this obj into it? I took the example of an Excel file, but my question would extend to any kind of binary file. Thank you in advance for your input Sebastien [[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] POSIX system oddities
Duh !!! Thanks. From: Peter Langfelder Sent: Sunday, March 29, 2020 20:12 To: Sebastien Bihorel Cc: r-help@r-project.org Subject: Re: [R] POSIX system oddities The time has changed from "standard" (EST) to "Daylight saving" (EDT) which shaves off 1 hour. Peter On Sun, Mar 29, 2020 at 5:03 PM Sebastien Bihorel via R-help mailto:r-help@r-project.org>> wrote: Hi, Why is there less number of seconds on 03/10/2019 in the internal POSIX system? The difference between the previous or the next day eems to be exactly 1 hour. I could not find anything in the manuals on CRAN. > dates <- as.POSIXct(sprintf('03/%s/2019',9:12), format = '%m/%d/%Y') > dates [1] "2019-03-09 EST" "2019-03-10 EST" "2019-03-11 EDT" "2019-03-12 EDT" > diff(as.numeric(dates[1:2])) [1] 86400 > diff(as.numeric(dates[2:3])) [1] 82800 > diff(as.numeric(dates[3:4])) [1] 86400 [[alternative HTML version deleted]] __ R-help@r-project.org<mailto: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] POSIX system oddities
Hi, Why is there less number of seconds on 03/10/2019 in the internal POSIX system? The difference between the previous or the next day eems to be exactly 1 hour. I could not find anything in the manuals on CRAN. > dates <- as.POSIXct(sprintf('03/%s/2019',9:12), format = '%m/%d/%Y') > dates [1] "2019-03-09 EST" "2019-03-10 EST" "2019-03-11 EDT" "2019-03-12 EDT" > diff(as.numeric(dates[1:2])) [1] 86400 > diff(as.numeric(dates[2:3])) [1] 82800 > diff(as.numeric(dates[3:4])) [1] 86400 [[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] Can file size affect how na.strings operates in a read.table call?
Thanks Bill and Jeff strip.white did not change the outcomes. However, your inputs led me to compare the raw content of the files (ie, outside of an IDE) and found difference in how the apparent -99 were stored. In the big file, some -99 are stored as floats rather than integers and thus included a decimal point and trailing zeros. The creation of the smaller files resulted in the removal of the decimal point and trailing zeros, explaining why read.table provided the "right " response on these smaller files. So, it looks like this is the problem and that some additional post-processing may be warranted. Thanks for the hints. From: William Dunlap Sent: Thursday, November 14, 2019 11:51 To: Jeff Newmiller Cc: Sebastien Bihorel ; r-help@r-project.org Subject: Re: [R] Can file size affect how na.strings operates in a read.table call? read.table (and friends) also have the strip.white argument: > s <- "A,B,C\n0,0,0\n1,-99,-99\n2,-99 ,-99\n3, -99, -99\n" > read.csv(text=s, header=TRUE, na.strings="-99", strip.white=TRUE) A B C 1 0 0 0 2 1 NA NA 3 2 NA NA 4 3 NA NA > read.csv(text=s, header=TRUE, na.strings="-99", strip.white=FALSE) A B C 1 0 0 0 2 1 NA NA 3 2 -99 NA 4 3 -99 -99 Bill Dunlap TIBCO Software wdunlap tibco.com<http://tibco.com> On Thu, Nov 14, 2019 at 8:35 AM Jeff Newmiller mailto:jdnew...@dcn.davis.ca.us>> wrote: Consider the following sample: # s <- "A,B,C 0,0,0 1,-99,-99 2,-99 ,-99 3, -99, -99 " dta_notok <- read.csv( text = s , header=TRUE , na.strings = c( "-99", "" ) ) dta_ok <- read.csv( text = s , header=TRUE , na.strings = c( "-99", " -99" , "-99 ", "" ) ) library(data.table) fdt_ok <- fread( text = s, na.strings=c( "-99", "" ) ) fdta_ok <- as.data.frame( fdt_ok ) # Leading and trailing spaces cause problems. The data.table::fread function has a strip.white argument that defaults to TRUE, but the resulting object is a data.table which has different semantics than a data.frame. On Thu, 14 Nov 2019, Sebastien Bihorel wrote: > The data file is a csv file. Some text variables contain spaces. > > "Check for extraneous spaces" > Are there specific locations that would be more critical than others? > > > ____________ > From: Jeff Newmiller > mailto:jdnew...@dcn.davis.ca.us>> > Sent: Thursday, November 14, 2019 10:52 > To: Sebastien Bihorel > mailto:sebastien.biho...@cognigencorp.com>>; > Sebastien > Bihorel via R-help mailto:r-help@r-project.org>>; > r-help@r-project.org<mailto:r-help@r-project.org> > mailto:r-help@r-project.org>> > Subject: Re: [R] Can file size affect how na.strings operates in a > read.table call? > Check for extraneous spaces. You may need more variations of the na.strings. > > On November 14, 2019 7:40:42 AM PST, Sebastien Bihorel via R-help > mailto:r-help@r-project.org>> wrote: > >Hi, > > > >I have this generic function to read ASCII data files. It is > >essentially a wrapper around the read.table function. My function is > >used in a large variety of situations and has no a priori knowledge > >about the data file it is asked to read. Nothing is known about file > >size, variable types, variable names, or data table dimensions. > > > >One argument of my function is na.strings which is passed down to > >read.table. > > > >Recently, a user tried to read a data file of ~ 80 Mo (~ 93000 rows by > >~ 160 columns) using na.strings = c('-99', '.') with the intention of > >interpreting '.' and '-99' > >strings as the internal missing data NA. Dots were converted to NA > >appropriately. However, not all -99 values in the data were interpreted > >as NA. In some variables, -99 were converted to NA, while in others -99 > >was read as a number. More surprisingly, when the data file was cut in > >smaller chunks (ie, by dropping either rows or columns) saved in > >multiple files, the function calls applied on the new data files > >resulted in the correct conversion of the -99 values into NAs. > > > >In all cases, the data frames produced by read.table contained the > >expected number of records. > > > >While, on face value, it appears that file size affects how the > >na.strings argument operates, I wondering if there is something else at > >play here. > > > >Unfortunately, I cannot share th
Re: [R] Can file size affect how na.strings operates in a read.table call?
The data file is a csv file. Some text variables contain spaces. "Check for extraneous spaces" Are there specific locations that would be more critical than others? From: Jeff Newmiller Sent: Thursday, November 14, 2019 10:52 To: Sebastien Bihorel ; Sebastien Bihorel via R-help ; r-help@r-project.org Subject: Re: [R] Can file size affect how na.strings operates in a read.table call? Check for extraneous spaces. You may need more variations of the na.strings. On November 14, 2019 7:40:42 AM PST, Sebastien Bihorel via R-help wrote: >Hi, > >I have this generic function to read ASCII data files. It is >essentially a wrapper around the read.table function. My function is >used in a large variety of situations and has no a priori knowledge >about the data file it is asked to read. Nothing is known about file >size, variable types, variable names, or data table dimensions. > >One argument of my function is na.strings which is passed down to >read.table. > >Recently, a user tried to read a data file of ~ 80 Mo (~ 93000 rows by >~ 160 columns) using na.strings = c('-99', '.') with the intention of >interpreting '.' and '-99' >strings as the internal missing data NA. Dots were converted to NA >appropriately. However, not all -99 values in the data were interpreted >as NA. In some variables, -99 were converted to NA, while in others -99 >was read as a number. More surprisingly, when the data file was cut in >smaller chunks (ie, by dropping either rows or columns) saved in >multiple files, the function calls applied on the new data files >resulted in the correct conversion of the -99 values into NAs. > >In all cases, the data frames produced by read.table contained the >expected number of records. > >While, on face value, it appears that file size affects how the >na.strings argument operates, I wondering if there is something else at >play here. > >Unfortunately, I cannot share the data file for confidentiality reason >but was wondering if you could suggest some checks I could perform to >get to the bottom on this issue. > >Thank you in advance for your help and sorry for the lack of >reproducible example. > > >__ >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. -- Sent from my phone. Please excuse my brevity. [[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] Can file size affect how na.strings operates in a read.table call?
Hi, I have this generic function to read ASCII data files. It is essentially a wrapper around the read.table function. My function is used in a large variety of situations and has no a priori knowledge about the data file it is asked to read. Nothing is known about file size, variable types, variable names, or data table dimensions. One argument of my function is na.strings which is passed down to read.table. Recently, a user tried to read a data file of ~ 80 Mo (~ 93000 rows by ~ 160 columns) using na.strings = c('-99', '.') with the intention of interpreting '.' and '-99' strings as the internal missing data NA. Dots were converted to NA appropriately. However, not all -99 values in the data were interpreted as NA. In some variables, -99 were converted to NA, while in others -99 was read as a number. More surprisingly, when the data file was cut in smaller chunks (ie, by dropping either rows or columns) saved in multiple files, the function calls applied on the new data files resulted in the correct conversion of the -99 values into NAs. In all cases, the data frames produced by read.table contained the expected number of records. While, on face value, it appears that file size affects how the na.strings argument operates, I wondering if there is something else at play here. Unfortunately, I cannot share the data file for confidentiality reason but was wondering if you could suggest some checks I could perform to get to the bottom on this issue. Thank you in advance for your help and sorry for the lack of reproducible example. __ 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] read.table and NaN
My bad, Bert My point is that my function/framework has very minimal expectations about the source data (mostly, that it is a rectangular shape table of data separated by some separator) and does not have any a-priori knowledge about what the first, second, etc columns in the data files must contain so while it would be possible to pass down some class vector which would be passed down as the colClasses argument to read.table, it is not necessarily reasonable in the context of the overall framework. I guess I was surprised that read.table interprets NaN in an input file as the internal "Not a number" rather than as a string... there is nothing in the ?read.table about that. Anyways, as I said, I need to think more about this in the context of the framework where this function operates... Thanks for the input From: Bert Gunter Sent: Thursday, October 24, 2019 10:39 To: Sebastien Bihorel Cc: r-help@r-project.org Subject: Re: [R] read.table and NaN Not so. Read ?read.table carefully. You can use "NA" as a default. Moreover, you **specified** that you want NaN read as character, which means that any column containing NaN **must** be character. That's part of the specification for data frames (all columns must be one data type). So either change your specfication or change your data structure. And, incidentally, my first name is "Bert" . Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, Oct 24, 2019 at 6:43 AM Sebastien Bihorel mailto:sebastien.biho...@cognigencorp.com>> wrote: Thanks Gunter It seems that one has to know the structure of the data and adapt the read.table call accordingly. I am working on a framework that is meant to process data files with unknown structure, so I have to think a bit more about that... From: Bert Gunter mailto:bgunter.4...@gmail.com>> Sent: Thursday, October 24, 2019 00:08 To: Sebastien Bihorel mailto:sebastien.biho...@cognigencorp.com>> Cc: r-help@r-project.org<mailto:r-help@r-project.org> mailto:r-help@r-project.org>> Subject: Re: [R] read.table and NaN Like this? con <- textConnection(object = 'A,B\n1,NaN\nNA,2') > tmp <- read.table(con, header = TRUE, sep = ',', na.strings = '', > stringsAsFactors = FALSE, + colClasses = c("numeric", "character")) > close.connection(con) > tmp A B 1 1 NaN 2 NA 2 > class(tmp[,1]) [1] "numeric" > class(tmp[,2]) [1] "character" > tmp[,2] [1] "NaN" "2" Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Oct 23, 2019 at 6:31 PM Sebastien Bihorel via R-help mailto:r-help@r-project.org>> wrote: Hi, Is there a way to make read.table consider NaN as a string of characters rather than the internal NaN? Changing the na.strings argument does not seems to have any effect on how R interprets the NaN string (while is does not the the NA string) con <- textConnection(object = 'A,B\n1,NaN\nNA,2') tmp <- read.table(con, header = TRUE, sep = ',', na.strings = '', stringsAsFactors = FALSE) close.connection(con) tmp class(tmp[,1]) class(tmp[,2]) __ R-help@r-project.org<mailto: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.
Re: [R] read.table and NaN
Thanks Gunter It seems that one has to know the structure of the data and adapt the read.table call accordingly. I am working on a framework that is meant to process data files with unknown structure, so I have to think a bit more about that... From: Bert Gunter Sent: Thursday, October 24, 2019 00:08 To: Sebastien Bihorel Cc: r-help@r-project.org Subject: Re: [R] read.table and NaN Like this? con <- textConnection(object = 'A,B\n1,NaN\nNA,2') > tmp <- read.table(con, header = TRUE, sep = ',', na.strings = '', > stringsAsFactors = FALSE, + colClasses = c("numeric", "character")) > close.connection(con) > tmp A B 1 1 NaN 2 NA 2 > class(tmp[,1]) [1] "numeric" > class(tmp[,2]) [1] "character" > tmp[,2] [1] "NaN" "2" Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Oct 23, 2019 at 6:31 PM Sebastien Bihorel via R-help mailto:r-help@r-project.org>> wrote: Hi, Is there a way to make read.table consider NaN as a string of characters rather than the internal NaN? Changing the na.strings argument does not seems to have any effect on how R interprets the NaN string (while is does not the the NA string) con <- textConnection(object = 'A,B\n1,NaN\nNA,2') tmp <- read.table(con, header = TRUE, sep = ',', na.strings = '', stringsAsFactors = FALSE) close.connection(con) tmp class(tmp[,1]) class(tmp[,2]) __ R-help@r-project.org<mailto: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] read.table and NaN
Hi, Is there a way to make read.table consider NaN as a string of characters rather than the internal NaN? Changing the na.strings argument does not seems to have any effect on how R interprets the NaN string (while is does not the the NA string) con <- textConnection(object = 'A,B\n1,NaN\nNA,2') tmp <- read.table(con, header = TRUE, sep = ',', na.strings = '', stringsAsFactors = FALSE) close.connection(con) tmp class(tmp[,1]) class(tmp[,2]) __ 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] Problem with save/load across R versions and OS
Hi, I managed to transfer my object trough dput/dget and a text file export. I will look into stripping the function for the reprex creation when I have more time (this is a ginormous function)... Thanks to your input and Bert's - Original Message - From: "Duncan Murdoch" To: "Sebastien Bihorel" Cc: r-help@r-project.org Sent: Wednesday, July 17, 2019 3:04:46 PM Subject: Re: [R] Problem with save/load across R versions and OS On 17/07/2019 2:02 p.m., Sebastien Bihorel wrote: > Hi, > > Indeed the S4 object is a class provided by a contributed package. However, > the windows machine that reads the .rds fine does not even have the package > installed. > > I also confirm that I used readRDS (loadRDS was a typo on my part, sorry). > > In this case, I cannot provide a reprex as the contributed package function > that creates the S4 object connects to a local database with secured access. > I could send the code, but only the authorized people could run it. This is > not the ideal situation for problem solving... > > I was wondering if there was a pathway through serialize / unserialize. I > tried but I could not find the way to properly write and read the serialized > object. I don't know about that approach. You can probably produce a reprex, it'll just be work: copy the function from the contributed package, and edit it so that the line that reads from the database just generates some fake data in a similar format. If you can make it reproducible, then cut out as much stuff as possible, keeping it reproducible, and post the final minimal reprex. It's likely to take some time, but also likely to lead to a solution (either by you, when you notice a bug in the contributed package and can fix it, or by one of us, when you post the reprex and we dig in). Duncan Murdoch __ 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] Problem with save/load across R versions and OS
Hi, Indeed the S4 object is a class provided by a contributed package. However, the windows machine that reads the .rds fine does not even have the package installed. I also confirm that I used readRDS (loadRDS was a typo on my part, sorry). In this case, I cannot provide a reprex as the contributed package function that creates the S4 object connects to a local database with secured access. I could send the code, but only the authorized people could run it. This is not the ideal situation for problem solving... I was wondering if there was a pathway through serialize / unserialize. I tried but I could not find the way to properly write and read the serialized object. Thanks - Original Message - From: "Duncan Murdoch" To: "Sebastien Bihorel" , r-help@r-project.org Sent: Wednesday, July 17, 2019 10:42:13 AM Subject: Re: [R] Problem with save/load across R versions and OS On 17/07/2019 4:39 a.m., Sebastien Bihorel wrote: > Hi, > > I am trying to transfer an S4 object from a machine working with CentOS 7.2 / > R 3.4.3 to another one running Linux Mint 19 / R 3.6.0. If I save the object > using saveRDS in obj.rds, loadRDS returns an "unknown input format" error on > my Linux Mint machine. Interestingly enough, obj.rds loads just fine in a 3rd > machine running Windows Server 2012 / R 3.4.3. I tried also using save and > load and various values of the ascii and compression arguments, but still no > cigar... > > Do you have recommendations on how to successfully transfer my object to my > Linux Mint machine? > Normally such a transfer should just work. Reasons why it might not: - The error is being triggered by a contributed package somehow. Do contributed package versions match? - There's no loadRDS function in base R, the base R function is readRDS. If that's not just a typo above, then the loadRDS function you're using doesn't work. Use the base package functions instead. - There's a bug in R. In any case, we can't do much to help you without a reproducible example. Duncan Murdoch __ 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] Problem with save/load across R versions and OS
Hi, Yes, I tried save/load... same failure. But I did not yet try dump/source or dput/dget. I will From: "Bert Gunter" To: "Sebastien Bihorel" Cc: "R-help" Sent: Wednesday, July 17, 2019 10:27:24 AM Subject: Re: [R] Problem with save/load across R versions and OS Did you try plain save/load ?? Also ?dump/source ?dput/dget Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Jul 17, 2019 at 1:38 AM Sebastien Bihorel < [ mailto:sebastien.biho...@cognigencorp.com | sebastien.biho...@cognigencorp.com ] > wrote: Hi, I am trying to transfer an S4 object from a machine working with CentOS 7.2 / R 3.4.3 to another one running Linux Mint 19 / R 3.6.0. If I save the object using saveRDS in obj.rds, loadRDS returns an "unknown input format" error on my Linux Mint machine. Interestingly enough, obj.rds loads just fine in a 3rd machine running Windows Server 2012 / R 3.4.3. I tried also using save and load and various values of the ascii and compression arguments, but still no cigar... Do you have recommendations on how to successfully transfer my object to my Linux Mint machine? Thanks Sebastien __ [ mailto:R-help@r-project.org | R-help@r-project.org ] mailing list -- To UNSUBSCRIBE and more, see [ https://stat.ethz.ch/mailman/listinfo/r-help | https://stat.ethz.ch/mailman/listinfo/r-help ] PLEASE do read the posting guide [ http://www.r-project.org/posting-guide.html | 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] Problem with save/load across R versions and OS
Hi, I am trying to transfer an S4 object from a machine working with CentOS 7.2 / R 3.4.3 to another one running Linux Mint 19 / R 3.6.0. If I save the object using saveRDS in obj.rds, loadRDS returns an "unknown input format" error on my Linux Mint machine. Interestingly enough, obj.rds loads just fine in a 3rd machine running Windows Server 2012 / R 3.4.3. I tried also using save and load and various values of the ascii and compression arguments, but still no cigar... Do you have recommendations on how to successfully transfer my object to my Linux Mint machine? Thanks Sebastien __ 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] Control the variable order after multiple declarations using within
Thanks all for your inputs. - Original Message - From: "Duncan Murdoch" To: "Jeff Newmiller" , r-help@r-project.org, "Eric Berger" , "Richard O'Keefe" Cc: "Sebastien Bihorel" Sent: Wednesday, July 3, 2019 12:52:55 PM Subject: Re: [R] Control the variable order after multiple declarations using within On 03/07/2019 12:42 p.m., Jeff Newmiller wrote: > Dummy columns do have some drawbacks though, if you find yourself working > with large data frames. The dummy columns waste memory and time as compared > to either reorganizing columns after the `within` or using separate > sequential `with` expressions as I previously suggested. I think mutate > avoids this overhead also. I think mutate() has only a very small advantage over within(). Neither one of them is flexible about the order of columns in the final result. In the OPs example, mutate creates the variables in the desired order, but it would be no better if the desired order had been a, c, b, because b is needed for the calculation of c, so it would be created first. Eric's suggestion within(df, {b<-a*2; c<-b*3})[c("a","b","c")] is the best so far, though I'd probably write it as within(df, {b<-a*2; c<-b*3})[, c("a","b","c")] just to avoid confusing my future self and make clear that I'm talking about specifying an order for the columns. And if you really, really want everything to happen within the call, just create the variables in the reverse order to what you want, e.g. within(df, {c <- a; b<-a*2; c<-b*3}) but to me that is a lot less clear than Eric's solution. Duncan Murdoch > > On July 3, 2019 8:25:32 AM PDT, Eric Berger wrote: >> Nice suggestion, Richard. >> >> On Wed, Jul 3, 2019 at 4:28 PM Richard O'Keefe >> wrote: >> >>> Why not set all the new columns to dummy values to get the order you >>> want and then set them to their final values in the order that works >>> for that? >>> >>> >>> On Thu, 4 Jul 2019 at 00:12, Kevin Thorpe >>> wrote: >>> >>>> >>>>> On Jul 3, 2019, at 3:15 AM, Sebastien Bihorel < >>>> sebastien.biho...@cognigencorp.com> wrote: >>>>> >>>>> Hi, >>>>> >>>>> The within function can be used to modify data.frames (among >> other >>>> objects). One can even provide multiple expressions to modify the >>>> data.frame by more than one expression. However, when new variables >> are >>>> created, they seem to be inserted in the data.frame in the opposite >> order >>>> they were declared: >>>>> >>>>>> df <- data.frame(a=1) >>>>>> within(df, {b<-a*2; c<-b*3}) >>>>> a c b >>>>> 1 1 6 2 >>>>> >>>>> Is there a way to insert the variables in an order consistent >> with the >>>> order of declaration (ie, a, b, c)? >>>>> >>>> >>>> One way is to use mutate() from the dplyr package. >>>> >>>> >>>>> Thanks >>>>> >>>>> Sebastien >>>>> >>>>> __ >>>>> 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. >>>> >>>> >>>> -- >>>> Kevin E. Thorpe >>>> Head of Biostatistics, Applied Health Research Centre (AHRC) >>>> Li Ka Shing Knowledge Institute of St. Michael's >>>> Assistant Professor, Dalla Lana School of Public Health >>>> University of Toronto >>>> email: kevin.tho...@utoronto.ca Tel: 416.864.5776 Fax: >> 416.864.3016 >>>> >>>> __ >>>> 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. >>> >> >> [[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-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] Control the variable order after multiple declarations using within
Hi Eric, I was hoping to avoid post-processing the result of the within call. Sebastien From: "Eric Berger" To: "Sebastien Bihorel" Cc: "R mailing list" Sent: Wednesday, July 3, 2019 8:13:22 AM Subject: Re: [R] Control the variable order after multiple declarations using within Hi Sebastien, Your 'within' command returns a dataframe. So without changing the call to within you have some options such as: df2 <- within(df, {b<-a*2; c<-b*3}) df2[c("a","b","c")] OR within(df, {b<-a*2; c<-b*3})[c("a","b","c")] OR within(df, {b<-a*2; c<-b*3})[c(1,3,2)] HTH, Eric On Wed, Jul 3, 2019 at 10:14 AM Sebastien Bihorel < [ mailto:sebastien.biho...@cognigencorp.com | sebastien.biho...@cognigencorp.com ] > wrote: Hi, The within function can be used to modify data.frames (among other objects). One can even provide multiple expressions to modify the data.frame by more than one expression. However, when new variables are created, they seem to be inserted in the data.frame in the opposite order they were declared: > df <- data.frame(a=1) > within(df, {b<-a*2; c<-b*3}) a c b 1 1 6 2 Is there a way to insert the variables in an order consistent with the order of declaration (ie, a, b, c)? Thanks Sebastien __ [ mailto:R-help@r-project.org | R-help@r-project.org ] mailing list -- To UNSUBSCRIBE and more, see [ https://stat.ethz.ch/mailman/listinfo/r-help | https://stat.ethz.ch/mailman/listinfo/r-help ] PLEASE do read the posting guide [ http://www.r-project.org/posting-guide.html | 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.
Re: [R] Control the variable order after multiple declarations using within
Hi Kevin, I was hoping to stay within base R functionality. Thanks - Original Message - From: "Kevin Thorpe" To: "Sebastien Bihorel" Cc: "R Help Mailing List" Sent: Wednesday, July 3, 2019 8:11:51 AM Subject: Re: [R] Control the variable order after multiple declarations using within > On Jul 3, 2019, at 3:15 AM, Sebastien Bihorel > wrote: > > Hi, > > The within function can be used to modify data.frames (among other objects). > One can even provide multiple expressions to modify the data.frame by more > than one expression. However, when new variables are created, they seem to be > inserted in the data.frame in the opposite order they were declared: > >> df <- data.frame(a=1) >> within(df, {b<-a*2; c<-b*3}) > a c b > 1 1 6 2 > > Is there a way to insert the variables in an order consistent with the order > of declaration (ie, a, b, c)? > One way is to use mutate() from the dplyr package. > Thanks > > Sebastien > > __ > 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. -- Kevin E. Thorpe Head of Biostatistics, Applied Health Research Centre (AHRC) Li Ka Shing Knowledge Institute of St. Michael's Assistant Professor, Dalla Lana School of Public Health University of Toronto email: kevin.tho...@utoronto.ca Tel: 416.864.5776 Fax: 416.864.3016 __ 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] Control the variable order after multiple declarations using within
Hi, The within function can be used to modify data.frames (among other objects). One can even provide multiple expressions to modify the data.frame by more than one expression. However, when new variables are created, they seem to be inserted in the data.frame in the opposite order they were declared: > df <- data.frame(a=1) > within(df, {b<-a*2; c<-b*3}) a c b 1 1 6 2 Is there a way to insert the variables in an order consistent with the order of declaration (ie, a, b, c)? Thanks Sebastien __ 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] Can one perform a dry run of a package installation?
Thanks - Original Message - From: "Duncan Murdoch" To: "Sebastien Bihorel" , r-help@r-project.org Sent: Tuesday, April 9, 2019 7:29:50 PM Subject: Re: [R] Can one perform a dry run of a package installation? On 09/04/2019 5:46 p.m., Sebastien Bihorel wrote: > Hi, > > Is there a way to do a dry run of install.packages() or update.packages() to > simulate how an R environment would be modified by the installation or update > of a particular set of packages (with their dependencies)? > > I am particularly interested in finding how dependencies would be recursively > updated to newer versions. Set the `lib` parameter of `install.packages` to an empty directory, and see what gets installed there. Duncan Murdoch __ 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] Can one perform a dry run of a package installation?
Hi, Is there a way to do a dry run of install.packages() or update.packages() to simulate how an R environment would be modified by the installation or update of a particular set of packages (with their dependencies)? I am particularly interested in finding how dependencies would be recursively updated to newer versions. Thanks __ 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] How to list recursive package dependency prior to installation/upgrade of a package
That is great! Is there a way to know version required in the dependent packages? From: "William Dunlap" To: "Sebastien Bihorel" Cc: r-help@r-project.org Sent: Thursday, March 14, 2019 3:50:58 PM Subject: Re: [R] How to list recursive package dependency prior to installation/upgrade of a package > tools::package_dependencies("lme4") $lme4 [1] "Matrix" "methods" "stats" "graphics" "grid" "splines" [7] "utils" "parallel" "MASS" "lattice" "boot" "nlme" [13] "minqa" "nloptr" "Rcpp" "RcppEigen" > tools::package_dependencies("lme4", recursive=TRUE) $lme4 [1] "Matrix" "methods" "stats" "graphics" "grid" "splines" [7] "utils" "parallel" "MASS" "lattice" "boot" "nlme" [13] "minqa" "nloptr" "Rcpp" "RcppEigen" "grDevices" Use reverse=TRUE to list packages that depend on the given package. Bill Dunlap TIBCO Software wdunlap [ http://tibco.com/ | tibco.com ] On Thu, Mar 14, 2019 at 12:09 PM Sebastien Bihorel < [ mailto:sebastien.biho...@cognigencorp.com | sebastien.biho...@cognigencorp.com ] > wrote: Hi Is there an elegant way to recursive list all dependencies of a package prior to its installation or upgrade? I am particularly interested in finding which of the packages currently installed in my test/production environment would require an upgrade prior to actual installation/upgrade of a package. Can the packrat package help with this? Thank you __ [ mailto:R-help@r-project.org | R-help@r-project.org ] mailing list -- To UNSUBSCRIBE and more, see [ https://stat.ethz.ch/mailman/listinfo/r-help | https://stat.ethz.ch/mailman/listinfo/r-help ] PLEASE do read the posting guide [ http://www.r-project.org/posting-guide.html | 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] How to list recursive package dependency prior to installation/upgrade of a package
Hi Is there an elegant way to recursive list all dependencies of a package prior to its installation or upgrade? I am particularly interested in finding which of the packages currently installed in my test/production environment would require an upgrade prior to actual installation/upgrade of a package. Can the packrat package help with this? Thank you __ 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] Stratifying data with xyplot
Hi, I am a big user/fan of the lattice package for plotting. As far as I know, lattice only offers one method to stratify data within a xyplot panel, using the groups arguments. A contrario, the ggplot package allow users to use different variables for coloring, setting the symbols, the line types or the size of symbols. This frequently comes handy. My question is whether any work has been done in the lattice ecosystem to reproduce this functionality? If so, I would greatly appreciate any pointers to the appropriate package documentation. Thank you Sebastien __ 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] Diff'ing 2 strings
Thanks for the clarification. - Original Message - From: "Duncan Murdoch" To: "Sebastien Bihorel" , "Jeff Newmiller" Cc: r-help@r-project.org Sent: Thursday, January 10, 2019 11:43:14 AM Subject: Re: [R] Diff'ing 2 strings On 10/01/2019 11:38 a.m., Sebastien Bihorel wrote: > Yep, I did. Got nothing. It does not come with R 3.4.3, which is the version > I can use. > > R CMD Rdiff comes with this version, but it is a shell command not a R > function. It is meant for diff'ing R output. It's in the tools package, so ?tools::Rdiff should get what you want even in that version. But as you note, it isn't a general purpose diff for character vectors, it is targeted at comparing R output files. Duncan Murdoch > > > - Original Message - > From: "Jeff Newmiller" > To: r-help@r-project.org, "Sebastien Bihorel" > , "Martin Møller Skarbiniks Pedersen" > > Cc: "R mailing list" > Sent: Thursday, January 10, 2019 10:49:15 AM > Subject: Re: [R] Diff'ing 2 strings > > Just type > > ?Rdiff > > it is in the preinstalled packages that come with R. > > On January 10, 2019 7:35:42 AM PST, Sebastien Bihorel > wrote: >>From which the diffobj package? >> >> >> From: "Martin Møller Skarbiniks Pedersen" >> To: "Sebastien Bihorel" >> Cc: "R mailing list" >> Sent: Thursday, January 10, 2019 2:35:15 AM >> Subject: Re: [R] Diff'ing 2 strings >> >> >> >> On Sat, Jan 5, 2019, 14:58 Sebastien Bihorel < [ >> mailto:sebastien.biho...@cognigencorp.com | >> sebastien.biho...@cognigencorp.com ] wrote: >> >> >> Hi, >> >> Does R include an equivalent of the linux diff command? >> >> >> >> >> yes. >> ?rdiff >> >> /martin >> >> >> [[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-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] Diff'ing 2 strings
Yep, I did. Got nothing. It does not come with R 3.4.3, which is the version I can use. R CMD Rdiff comes with this version, but it is a shell command not a R function. It is meant for diff'ing R output. - Original Message - From: "Jeff Newmiller" To: r-help@r-project.org, "Sebastien Bihorel" , "Martin Møller Skarbiniks Pedersen" Cc: "R mailing list" Sent: Thursday, January 10, 2019 10:49:15 AM Subject: Re: [R] Diff'ing 2 strings Just type ?Rdiff it is in the preinstalled packages that come with R. On January 10, 2019 7:35:42 AM PST, Sebastien Bihorel wrote: >From which the diffobj package? > > >From: "Martin Møller Skarbiniks Pedersen" >To: "Sebastien Bihorel" >Cc: "R mailing list" >Sent: Thursday, January 10, 2019 2:35:15 AM >Subject: Re: [R] Diff'ing 2 strings > > > >On Sat, Jan 5, 2019, 14:58 Sebastien Bihorel < [ >mailto:sebastien.biho...@cognigencorp.com | >sebastien.biho...@cognigencorp.com ] wrote: > > >Hi, > >Does R include an equivalent of the linux diff command? > > > > >yes. >?rdiff > >/martin > > > [[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. -- Sent from my phone. Please excuse my brevity. __ 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] Diff'ing 2 strings
>From which the diffobj package? From: "Martin Møller Skarbiniks Pedersen" To: "Sebastien Bihorel" Cc: "R mailing list" Sent: Thursday, January 10, 2019 2:35:15 AM Subject: Re: [R] Diff'ing 2 strings On Sat, Jan 5, 2019, 14:58 Sebastien Bihorel < [ mailto:sebastien.biho...@cognigencorp.com | sebastien.biho...@cognigencorp.com ] wrote: Hi, Does R include an equivalent of the linux diff command? yes. ?rdiff /martin [[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] Diff'ing 2 strings
Thanks Sorry my mention of "fairly complex strings" was indeed a bit vague, indeed. My code is building strings that contain \n characters so something that could be thought about as multiline strings. For comparing these strings, I was hoping to use something like the linux diff command which is smart enough to recognize these line chunks you mentioned and not just to a simple line-by-line comparison. I saw a few thread mentioning ?adist. I will look into that. Sebastien From: "Bert Gunter" To: "Sebastien Bihorel" Cc: "R-help" Sent: Saturday, January 5, 2019 10:19:42 AM Subject: Re: [R] Diff'ing 2 strings I do not know what you mean in your string context, as diff in Linux finds lines in files that differ. A reproducible example -- posting guide! -- would be most useful here. However, maybe something of the following strategy might be useful: 1. Break up your strings into lists of string "chunks" relevant for your context via strspit() . Using "" (empty character) as the "sep" string would break your strings into individual characters; "\n" would break it into "lines" separated by the return character; etc. 2. Compare your lists using e.g. lapply() and probably ?match and friends like ?setdiff You should also probably check out the stringr package to see if it contains what you need. Also, if this is gene sequence related, posting on the Bioconductor list rather than here is likely to be more fruitful. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sat, Jan 5, 2019 at 5:58 AM Sebastien Bihorel < [ mailto:sebastien.biho...@cognigencorp.com | sebastien.biho...@cognigencorp.com ] > wrote: Hi, Does R include an equivalent of the linux diff command? Ideally I would like to diff 2 fairly complex strings and extract the differences without having to save them on disk and using a system('diff file1 file2') command. Thanks Sebastien __ [ mailto:R-help@r-project.org | R-help@r-project.org ] mailing list -- To UNSUBSCRIBE and more, see [ https://stat.ethz.ch/mailman/listinfo/r-help | https://stat.ethz.ch/mailman/listinfo/r-help ] PLEASE do read the posting guide [ http://www.r-project.org/posting-guide.html | 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] Diff'ing 2 strings
Hi, Does R include an equivalent of the linux diff command? Ideally I would like to diff 2 fairly complex strings and extract the differences without having to save them on disk and using a system('diff file1 file2') command. Thanks Sebastien __ 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] Encoding issue
Hi Ivan, 0xe2 0x80 0x99 seems to be the UTF-8 hex code for Unicode Character 'RIGHT SINGLE QUOTATION MARK', which would make sense in the context. Using the encoding argument for the scan call does not change the outcome. Looking at the server side a bit more, some colleagues pointed out that the "râs" display could be a side-effect of encoding issue with Putty (which I used to connect to the remote server). Changing the setting of Putty display, I get the correct display "r’s"... However, that does not change anything to the gsub issue... Sebastien - Original Message - From: "Ivan Krylov" To: "Sebastien Bihorel" Cc: r-help@r-project.org Sent: Monday, November 5, 2018 2:34:02 PM Subject: Re: [R] Encoding issue On Mon, 5 Nov 2018 08:36:13 -0500 (EST) Sebastien Bihorel wrote: > [1] "râs" Interesting. This is what I get if I decode the bytes 72 e2 80 99 73 0a as latin-1 instead of UTF-8. They look like there is only three characters, but, actually, there is more: $ perl -CSD -Mcharnames=:full -MEncode=decode \ -E'for (split //, decode latin1 => pack "H*", "72e28099730a") { say ord, " ", $_, " ", charnames::viacode(ord) }' 114 r LATIN SMALL LETTER R 226 â LATIN SMALL LETTER A WITH CIRCUMFLEX 128 PADDING CHARACTER 153 SINGLE GRAPHIC CHARACTER INTRODUCER 115 s LATIN SMALL LETTER S 10 LINE FEED Does it help if you explicitly specify the file encoding by passing fileEncoding="UTF-8" argument to scan()? -- Best regards, Ivan __ 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] Encoding issue
Hi, I am having problems getting similar output when processing the same markdown files on 2 different Linux systems (one is a laptop with Linux Mint 18.3, the other is a production server running on CentOS 7). I think this boils down to an encoding issue but I am not sure if this is a system-wide issue or an R issue. So, this is what I have so far. I have this very small dummy html file (with the same md5sum on both systems) which only contains 3 characters. A "od -cx" call provides the same output in both systems: 000 r 342 200 231 s \n e27299800a73 The middle character is some form of single quote produced by the conversion of a ' character from markdown to html. Reading the same file in both systems and applying a gsub replace provide widely different results. On my laptop # environment variable: echo $LANG: en_US.UTF-8 > x <- scan('test.html', what='character', sep='\n') Read 1 item > x [1] "r’s" > gsub('\\s{2,}', ' ', x) [1] "r’s" > sessionInfo() R version 3.4.4 (2018-03-15) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Linux Mint 18.3 Matrix products: default BLAS: /usr/lib/libblas/libblas.so.3.6.0 LAPACK: /usr/lib/lapack/liblapack.so.3.6.0 locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_3.4.4 On the server # environment variable: echo $LANG: en_US.UTF-8 > x <- scan('test.html', what='character', sep='\n') Read 1 item > x [1] "râs" > gsub('\\s{2,}', ' ', x) [1] " " > sessionInfo() R version 3.4.3 (2017-11-30) Platform: x86_64-redhat-linux-gnu (64-bit) Running under: CentOS Linux 7 (Core) Matrix products: default BLAS: /usr/lib64/R/lib/libRblas.so LAPACK: /usr/lib64/R/lib/libRlapack.so locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] compiler_3.4.3 (The overarching issue is that I have to use the production server for SOP reasons, so I cannot simply ignore the problem and use my laptop). I would appreciate any suggestions on how to approach this issue. __ 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] Question about function scope
Thanks a lot Eric, I think you are on the same page as Duncan (at least with his 2nd option). I will definitively explore this. From: "Eric Berger" To: "Duncan Murdoch" Cc: "Sebastien Bihorel" , "R mailing list" Sent: Tuesday, October 30, 2018 4:17:30 PM Subject: Re: [R] Question about function scope Hi Sebastien, I like Duncan's response. An alternative approach is to pass around environments, as in the following: bar1 <- function(e) { e$x <- e$y <- e$z <- 1 cat(sprintf('bar1: x=%d, y=%d, z=%d\n', e$x, e$y, e$z)) } bar2 <- function(e) { e$x <- e$y <- e$z <- 2 cat(sprintf('bar2: x=%d, y=%d, z=%d\n', e$x, e$y, e$z)) } foo <- function(a=1, b=2, c=0, e){ # some setup code dummy <- a + b e$x <- e$y <- e$z <- 0 # here is my scope problem if (c==1) bar1(e) if (c==2) bar2(e) # some more code cat(sprintf('foo: x=%d, y=%d, z=%d\n', e$x, e$y, e$z)) } e <- new.env() e$x <- NA e$y <- NA e$z <- NA foo(c=0,e=e) foo(c=1,e=e) foo(c=2,e=e) HTH, Eric On Tue, Oct 30, 2018 at 10:13 PM Duncan Murdoch < [ mailto:murdoch.dun...@gmail.com | murdoch.dun...@gmail.com ] > wrote: On 30/10/2018 3:56 PM, Sebastien Bihorel wrote: > Hi, > > From the R user manual, I have a basic understanding of the scope of function > evaluation but have a harder time understanding how to mess with > environments. > > My problem can be summarized by the code shown at the bottom: > - the foo function performs some steps including the assignment of default > values to 3 objects: x, y, z > - at some point, I would like to call either the bar1 or bar2 function based > upon the value of the c argument of the foo function. These functions assign > different values to the x, y, z variables. > - then foo should move on and do other cool stuff > > Based upon default R scoping, the x, y, and z variables inside the bar1 and > bar2 functions are not in the same environment as the x, y, and z variables > created inside the foo function. > > Can I modify the scope of evaluation of bar1 and bar2 so that x, y, and z > created inside the foo function are modified? > > PS: > - I know about "<<-" but, in my real code (which I cannot share, sorry), foo > is already called within other functions and x, y, and z variables do not > exist in the top-level environment and are not returned by foo. So "<<-" does > not work (per manual: " Only when <<- has been used in a function that was > returned as the value of another function will the special behavior described > here occur. ") I haven't looked up that quote, but it is likely describing a situation that isn't relevant to you. For you, the important part is that bar1 and bar2 must be created within foo. They don't need to be returned from it. So my edit below of your code should do what you want. foo <- function(a=1, b=2, c=0){ bar1 <- function(){ x <<- 1 y <<- 1 z <<- 1 cat(sprintf('bar1: x=%d, y=%d, z=%d\n', x, y, z)) } bar2 <- function(){ x <<- 2 y <<- 2 z <<- 2 cat(sprintf('bar2: x=%d, y=%d, z=%d\n', x, y, z)) } # some setup code dummy <- a + b x <- y <- z <- 0 # here is my scope problem if (c==1) bar1() if (c==2) bar2() # some more code cat(sprintf('foo: x=%d, y=%d, z=%d\n', x, y, z)) } foo(c=0) foo(c=1) foo(c=2) I get this output: > foo(c=0) foo: x=0, y=0, z=0 > foo(c=1) bar1: x=1, y=1, z=1 foo: x=1, y=1, z=1 > foo(c=2) bar2: x=2, y=2, z=2 foo: x=2, y=2, z=2 Duncan Murdoch __ [ mailto:R-help@r-project.org | R-help@r-project.org ] mailing list -- To UNSUBSCRIBE and more, see [ https://stat.ethz.ch/mailman/listinfo/r-help | https://stat.ethz.ch/mailman/listinfo/r-help ] PLEASE do read the posting guide [ http://www.r-project.org/posting-guide.html | 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.
Re: [R] Question about function scope
That's cool! I think this solution would fit better with what my intended setup. Thanks a lot - Original Message - From: "Duncan Murdoch" To: "Sebastien Bihorel" , r-help@r-project.org Sent: Tuesday, October 30, 2018 4:18:51 PM Subject: Re: [R] Question about function scope Here's another modification to your code that also works. It's a lot uglier, but will allow bar1 and bar2 to be used in multiple functions, not just foo. bar1 <- function(env){ env$x <- 1 env$y <- 1 env$z <- 1 with(env, cat(sprintf('bar1: x=%d, y=%d, z=%d\n', x, y, z))) } bar2 <- function(env){ env$x <- 2 env$y <- 2 env$z <- 2 with(env, cat(sprintf('bar2: x=%d, y=%d, z=%d\n', x, y, z))) } foo <- function(a=1, b=2, c=0){ # some setup code dummy <- a + b x <- y <- z <- 0 # here is my scope problem if (c==1) bar1(environment()) if (c==2) bar2(environment()) # some more code cat(sprintf('foo: x=%d, y=%d, z=%d\n', x, y, z)) } foo(c=0) foo(c=1) foo(c=2) Duncan Murdoch __ 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] Question about function scope
Thanks Duncan for your quick reply. Ideally, I would want bar1 and bar2 to be independent functions, because they are huge in actuality and, as the actual foo function grows, I may end up with 10 different bar# functions. So I would like to separate them from foo as much as possible. - Original Message - From: "Duncan Murdoch" To: "Sebastien Bihorel" , r-help@r-project.org Sent: Tuesday, October 30, 2018 4:13:05 PM Subject: Re: [R] Question about function scope On 30/10/2018 3:56 PM, Sebastien Bihorel wrote: > Hi, > > From the R user manual, I have a basic understanding of the scope of > function evaluation but have a harder time understanding how to mess with > environments. > > My problem can be summarized by the code shown at the bottom: > - the foo function performs some steps including the assignment of default > values to 3 objects: x, y, z > - at some point, I would like to call either the bar1 or bar2 function based > upon the value of the c argument of the foo function. These functions assign > different values to the x, y, z variables. > - then foo should move on and do other cool stuff > > Based upon default R scoping, the x, y, and z variables inside the bar1 and > bar2 functions are not in the same environment as the x, y, and z variables > created inside the foo function. > > Can I modify the scope of evaluation of bar1 and bar2 so that x, y, and z > created inside the foo function are modified? > > PS: > - I know about "<<-" but, in my real code (which I cannot share, sorry), foo > is already called within other functions and x, y, and z variables do not > exist in the top-level environment and are not returned by foo. So "<<-" does > not work (per manual: " Only when <<- has been used in a function that was > returned as the value of another function will the special behavior described > here occur. ") I haven't looked up that quote, but it is likely describing a situation that isn't relevant to you. For you, the important part is that bar1 and bar2 must be created within foo. They don't need to be returned from it. So my edit below of your code should do what you want. foo <- function(a=1, b=2, c=0){ bar1 <- function(){ x <<- 1 y <<- 1 z <<- 1 cat(sprintf('bar1: x=%d, y=%d, z=%d\n', x, y, z)) } bar2 <- function(){ x <<- 2 y <<- 2 z <<- 2 cat(sprintf('bar2: x=%d, y=%d, z=%d\n', x, y, z)) } # some setup code dummy <- a + b x <- y <- z <- 0 # here is my scope problem if (c==1) bar1() if (c==2) bar2() # some more code cat(sprintf('foo: x=%d, y=%d, z=%d\n', x, y, z)) } foo(c=0) foo(c=1) foo(c=2) I get this output: > foo(c=0) foo: x=0, y=0, z=0 > foo(c=1) bar1: x=1, y=1, z=1 foo: x=1, y=1, z=1 > foo(c=2) bar2: x=2, y=2, z=2 foo: x=2, y=2, z=2 Duncan Murdoch __ 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] Question about function scope
Hi, >From the R user manual, I have a basic understanding of the scope of function >evaluation but have a harder time understanding how to mess with environments. My problem can be summarized by the code shown at the bottom: - the foo function performs some steps including the assignment of default values to 3 objects: x, y, z - at some point, I would like to call either the bar1 or bar2 function based upon the value of the c argument of the foo function. These functions assign different values to the x, y, z variables. - then foo should move on and do other cool stuff Based upon default R scoping, the x, y, and z variables inside the bar1 and bar2 functions are not in the same environment as the x, y, and z variables created inside the foo function. Can I modify the scope of evaluation of bar1 and bar2 so that x, y, and z created inside the foo function are modified? PS: - I know about "<<-" but, in my real code (which I cannot share, sorry), foo is already called within other functions and x, y, and z variables do not exist in the top-level environment and are not returned by foo. So "<<-" does not work (per manual: " Only when <<- has been used in a function that was returned as the value of another function will the special behavior described here occur. ") - In my real example, I have a few dozens of variables to transform in bar1 and bar2 so exporting a list bundling all the transform values then dispatching them in foo does not seem practical - currently, my best solution is to save the inner part of bar1 and bar2 in separate scripts and sourcing them in foo (that does not seem elegant...) - also, I know that, theoretically, I could put the content of bar1 and bar2 directly in foo, but as the number of cases handled by foo grows, the code will become way too long and hardly manageable. Thanks for your help ## bar1 <- function(){ x <- 1 y <- 1 z <- 1 cat(sprintf('bar1: x=%d, y=%d, z=%d\n', x, y, z)) } bar2 <- function(){ x <- 2 y <- 2 z <- 2 cat(sprintf('bar2: x=%d, y=%d, z=%d\n', x, y, z)) } foo <- function(a=1, b=2, c=0){ # some setup code dummy <- a + b x <- y <- z <- 0 # here is my scope problem if (c==1) bar1() if (c==2) bar2() # some more code cat(sprintf('foo: x=%d, y=%d, z=%d\n', x, y, z)) } foo(c=0) foo(c=1) foo(c=2) __ 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] Porbably bug in panel.abline
Paul Murrell posted some comments on [ https://github.com/deepayan/lattice/issues/8 | https://github.com/deepayan/lattice/issues/8 ] - Original Message - From: "Bert Gunter" To: "Sebastien Bihorel" Cc: "R-help" Sent: Monday, June 18, 2018 4:15:29 PM Subject: Re: [R] Porbably bug in panel.abline hmmm... Youre right: something subtle is occurring. Here is a simpler reproducible example that illustrates the issue: a <- 10 y <- x <- c(0,a) for(k in c(-1,0,1)){ print(xyplot( y~x, type = 'l', col="blue", panel = function(x,y,...){ panel.xyplot(x,y,...) panel.abline(c(a+k,-1), col="red") } ))} Somehow, the "drawable limits" seem to exclude the corners of the plotting rectangle. I would guess that this has something to do with how the plotting viewport is clipped, but that's just a guess. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, Jun 18, 2018 at 12:05 PM, Sebastien Bihorel < [ mailto:sebastien.biho...@cognigencorp.com | sebastien.biho...@cognigencorp.com ] > wrote: No, the intercept a^2 f the abline is exactly the upper limit of the data, so it is in the range. From: "Bert Gunter" < [ mailto:bgunter.4...@gmail.com | bgunter.4...@gmail.com ] > To: "Sebastien Bihorel" < [ mailto:sebastien.biho...@cognigencorp.com | sebastien.biho...@cognigencorp.com ] > Cc: "R-help" < [ mailto:r-help@r-project.org | r-help@r-project.org ] > Sent: Monday, June 18, 2018 2:28:21 PM Subject: Re: [R] Porbably bug in panel.abline Note that: xyplot( y~x, data = data, type = 'l', col="blue", panel = function(x,y,...){ panel.xyplot(x,y,...) panel.abline(c(a^2-1,-1), col="red") } ) works. The problem is a^2 is just above the "drawable" y axis limit (it is the intercept of the line at x=0 with slope -1, of course). This also explains all your other comments. Cheers, Bert -- Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, Jun 18, 2018 at 11:01 AM, Sebastien Bihorel < [ mailto:sebastien.biho...@cognigencorp.com | sebastien.biho...@cognigencorp.com ] > wrote: BQ_BEGIN Hi, I recently encountered situations in which reference lines are not drawn with the lattice panel.abline function. Please, consider the following example code: require(lattice) a <- runif(1,0,100) data <- data.frame(x=c(0,a^2), y=c(0,a^2)) xyplot( y~x, data = data, type = 'l', panel = function(x,y,...){ panel.xyplot(x,y,...) panel.abline(c(a^2,-1.0), col=2) } ) Adding noise (eg panel.abline(c(a^2+0.01,-1.0), col=2)) or adding some axis limits seems to bypass the problem. The problem also happens for different data source and abline coefficients: data <- data.frame(x=c(18,81), y=c(18,81)) ... panel.abline(c(99,-1.0), col=2) Thank you in advance for your feedback. Sebastien PS: the problem was also posted at [ https://github.com/deepayan/lattice/issues/8 | https://github.com/deepayan/lattice/issues/8 ] __ [ mailto:R-help@r-project.org | R-help@r-project.org ] mailing list -- To UNSUBSCRIBE and more, see [ https://stat.ethz.ch/mailman/listinfo/r-help | https://stat.ethz.ch/mailman/listinfo/r-help ] PLEASE do read the posting guide [ http://www.r-project.org/posting-guide.html | http://www.R-project.org/posting-guide.html ] and provide commented, minimal, self-contained, reproducible code. BQ_END __ 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] Porbably bug in panel.abline
No, the intercept a^2 f the abline is exactly the upper limit of the data, so it is in the range. From: "Bert Gunter" To: "Sebastien Bihorel" Cc: "R-help" Sent: Monday, June 18, 2018 2:28:21 PM Subject: Re: [R] Porbably bug in panel.abline Note that: xyplot( y~x, data = data, type = 'l', col="blue", panel = function(x,y,...){ panel.xyplot(x,y,...) panel.abline(c(a^2-1,-1), col="red") } ) works. The problem is a^2 is just above the "drawable" y axis limit (it is the intercept of the line at x=0 with slope -1, of course). This also explains all your other comments. Cheers, Bert -- Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, Jun 18, 2018 at 11:01 AM, Sebastien Bihorel < [ mailto:sebastien.biho...@cognigencorp.com | sebastien.biho...@cognigencorp.com ] > wrote: Hi, I recently encountered situations in which reference lines are not drawn with the lattice panel.abline function. Please, consider the following example code: require(lattice) a <- runif(1,0,100) data <- data.frame(x=c(0,a^2), y=c(0,a^2)) xyplot( y~x, data = data, type = 'l', panel = function(x,y,...){ panel.xyplot(x,y,...) panel.abline(c(a^2,-1.0), col=2) } ) Adding noise (eg panel.abline(c(a^2+0.01,-1.0), col=2)) or adding some axis limits seems to bypass the problem. The problem also happens for different data source and abline coefficients: data <- data.frame(x=c(18,81), y=c(18,81)) ... panel.abline(c(99,-1.0), col=2) Thank you in advance for your feedback. Sebastien PS: the problem was also posted at [ https://github.com/deepayan/lattice/issues/8 | https://github.com/deepayan/lattice/issues/8 ] __ [ mailto:R-help@r-project.org | R-help@r-project.org ] mailing list -- To UNSUBSCRIBE and more, see [ https://stat.ethz.ch/mailman/listinfo/r-help | https://stat.ethz.ch/mailman/listinfo/r-help ] PLEASE do read the posting guide [ http://www.r-project.org/posting-guide.html | 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] Porbably bug in panel.abline
Hi, I recently encountered situations in which reference lines are not drawn with the lattice panel.abline function. Please, consider the following example code: require(lattice) a <- runif(1,0,100) data <- data.frame(x=c(0,a^2), y=c(0,a^2)) xyplot( y~x, data = data, type = 'l', panel = function(x,y,...){ panel.xyplot(x,y,...) panel.abline(c(a^2,-1.0), col=2) } ) Adding noise (eg panel.abline(c(a^2+0.01,-1.0), col=2)) or adding some axis limits seems to bypass the problem. The problem also happens for different data source and abline coefficients: data <- data.frame(x=c(18,81), y=c(18,81)) ... panel.abline(c(99,-1.0), col=2) Thank you in advance for your feedback. Sebastien PS: the problem was also posted at https://github.com/deepayan/lattice/issues/8 __ 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] Calling the curve function with a character object converted into an expression
Thanks, I always get confused by expression evaluation, when and how to use call, do.call, eval, parse/deparse, and all that good stuff. I always have to read documentation 10 times and still does not want to stick in my brain. - Original Message - From: "Bert Gunter" <bgunter.4...@gmail.com> To: "Sebastien Bihorel" <sebastien.biho...@cognigencorp.com> Cc: "R-help" <r-help@r-project.org> Sent: Thursday, May 3, 2018 2:28:59 AM Subject: Re: [R] Calling the curve function with a character object converted into an expression Typo: should be NULL not NUL of course An alternative approach closer to your original attempt is to use do.call() to explicitly evaluate the expr argument: w <- "1 + x^2" do.call(curve, list(expr = parse(text = w), ylab ="y")) Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, May 2, 2018 at 10:35 PM, Bert Gunter <bgunter.4...@gmail.com> wrote: > Sebastian: > > This is somewhat arcane, perhaps even a bug (correction on this > welcomed). The problem is that the "expr" argument to curve() must be > an actual expression, not a call to parse that evaluates to an > expression. If you look at the code of curve() you'll see why > (substitute() does not evaluate expr in the code). Another simple > workaround other than sticking in the eval() call is this: > > myf <- function(x)NUL > body(myf)<- parse(text = "{1+x^2}") ## note the additional "{ }" > for safety, though not necessary here > ## this idiom will continue to work for any text. > > curve(myf, from = 0, to = 10) ## myf is now the name of a function > that executes the parsed text. > > *** I would appreciate any wiser R programmers correcting any > misunderstanding or error in my explanation *** > > Cheers, > Bert > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Wed, May 2, 2018 at 8:11 PM, Sebastien Bihorel > <sebastien.biho...@cognigencorp.com> wrote: >> >> Hi, >> >> Down a cascade of function calls, I want to use the curve function with an >> expression that is a variable. For various reason, this variable must be a >> character object and cannot be an expression as required by the curve >> function. How do I convert my variable into a expression that is accepted by >> curve? >> >> Thanks in advance for your help. >> >> ## The following attempts do not work >> >> myf <- '1+x^2' >> curve(myf, from = 0, to = 10) # obviously ! >> curve(parse(text=myf), from = 0, to = 10) # not sure why this does not work >> >> ## This works but does not feel elegant: >> eval(parse(text=sprintf('curve(%s, from = 0, to = 10)', myf))) >> >> __ >> 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-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] Calling the curve function with a character object converted into an expression
Hi, Down a cascade of function calls, I want to use the curve function with an expression that is a variable. For various reason, this variable must be a character object and cannot be an expression as required by the curve function. How do I convert my variable into a expression that is accepted by curve? Thanks in advance for your help. ## The following attempts do not work myf <- '1+x^2' curve(myf, from = 0, to = 10) # obviously ! curve(parse(text=myf), from = 0, to = 10) # not sure why this does not work ## This works but does not feel elegant: eval(parse(text=sprintf('curve(%s, from = 0, to = 10)', myf))) __ 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] Question about subset
Thanks. S. Elison provided a similar but apparently more general solution (see other post in thread). - Original Message - From: "David Winsemius" <dwinsem...@comcast.net> To: "Sebastien Bihorel" <sebastien.biho...@cognigencorp.com> Cc: r-help@r-project.org Sent: Monday, April 9, 2018 12:33:41 AM Subject: Re: [R] Question about subset Sent from my iPhone > On Apr 8, 2018, at 9:06 PM, Sebastien Bihorel > <sebastien.biho...@cognigencorp.com> wrote: > > Hi, > > The help page for subset states "subset: logical expression indicating > elements or rows to keep: missing values are taken as false." > > Before I try to re-invent the wheel, I would like to know if one of the base > or recommended packages would contain a variant of the subset function that > would consider missing values as true. > Just use a Boolean expression is.na(col)|(col==0) > Thanks > > __ > 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-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] Question about subset
Thanks. That works great! > df <- data.frame(x=c(1,1,NA,NA,2), y=c('a','a','a','b','b'), > z=c(TRUE,FALSE,TRUE,FALSE,TRUE)) > cond1 <- 'x==1' > cond2 <- 'x==1 & z' > df x y z 1 1 a TRUE 2 1 a FALSE 3 NA a TRUE 4 NA b FALSE 5 2 b TRUE > subset(df, subset = ifelse(is.na(eval(parse(text=cond1))), TRUE, > eval(parse(text=cond1 x y z 1 1 a TRUE 2 1 a FALSE 3 NA a TRUE 4 NA b FALSE > subset(df, subset = ifelse(is.na(eval(parse(text=cond2))), TRUE, > eval(parse(text=cond2 x yz 1 1 a TRUE 3 NA a TRUE - Original Message - From: "S Ellison" <s.elli...@lgcgroup.com> To: "Sebastien Bihorel" <sebastien.biho...@cognigencorp.com> Sent: Monday, April 9, 2018 8:31:55 AM Subject: RE: Question about subset > Before I try to re-invent the wheel, I would like to know if one of the base > or > recommended packages would contain a variant of the subset function that > would consider missing values as true. The subset argument to subset is something that evaluates to logical - a vector of True or False. If you wanted to treat missing values _in that_ as TRUE, wrap it in an ifelse: ifelse(is.na(condition), TRUE, condition) where condition can be a logical or an expression evaluating to logical. S Ellison *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] Question about subset
Hi, The help page for subset states "subset: logical expression indicating elements or rows to keep: missing values are taken as false." Before I try to re-invent the wheel, I would like to know if one of the base or recommended packages would contain a variant of the subset function that would consider missing values as true. Thanks __ 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] Equivalent of gtools::mixedsort in R base
Thanks. - Original Message - From: "Gabor Grothendieck" <ggrothendi...@gmail.com> To: "Sebastien Bihorel" <sebastien.biho...@cognigencorp.com> Cc: r-help@r-project.org Sent: Monday, March 12, 2018 3:49:10 PM Subject: Re: [R] Equivalent of gtools::mixedsort in R base split any mixed columns into letter and number columns and then order can be used on that: DF <- data.frame(x = c("a10", "a2", "a1")) o <- do.call("order", transform(DF, let = gsub("\\d", "", x), no = as.numeric(gsub("\\D", "", x)), x = NULL)) DF[o,, drop = FALSE ] On Mon, Mar 12, 2018 at 12:15 AM, Sebastien Bihorel <sebastien.biho...@cognigencorp.com> wrote: > Hi, > > Searching for functions that would order strings that mix characters and > numbers in a "natural" way (ie, "a1 a2 a10" instead of "a1 a10 a2"), I found > the mixedsort and mixedorder from the gtools package. > > Problems: > 1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call like > the order function does > 2- gtools has not been updated in 2.5 years > > Are you aware of an equivalent of this function in base R or a another > contributed package (with correction of problem #1)? > > Thanks > > __ > 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. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ 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] Equivalent of gtools::mixedsort in R base
Thanks for your reply. I take this is also a no to my question and appreciated the suggested mixedrank function and its usage with do.call. Thanks - Original Message - From: "Jeff Newmiller" <jdnew...@dcn.davis.ca.us> To: "Bert Gunter" <bgunter.4...@gmail.com> Cc: "Sebastien Bihorel" <sebastien.biho...@cognigencorp.com>, "R-help" <r-help@r-project.org> Sent: Monday, March 12, 2018 2:11:03 AM Subject: Re: [R] Equivalent of gtools::mixedsort in R base x <- c( "a1", "a10", "a2" ) y <- c( "b10", "b2", "a12", "ca1" ) DF <- expand.grid( x = x, y = y ) # randomize set.seed( 42 ) DF <- DF[ sample( nrow( DF ) ), ] # missing from gtools mixedrank <- function( x ) { seq.int( length( x ) )[ gtools::mixedorder(x) ] } o <- do.call( order, lapply( DF, mixedrank ) ) DF[ o, ] # or, as Bert suggests: myrank <- function( v ) { vu <- unique(v) vl <- regmatches( vu,regexec("^([A-Za-z]+)(\\d+)$",vu)) alph <- sapply( vl, function(s) s[2] ) digt <- as.integer( sapply( vl, function(s) s[3] ) ) o <- order( alph, digt ) vo <- ordered( v, levels=vu[ o ] ) } o2 <- do.call( order, lapply( DF, myrank ) ) DF[ o2, ] ?order ?ordered ?rank On Sun, 11 Mar 2018, Bert Gunter wrote: > ??? > >> y <- sort( c("a1","a2","a10","a12","a100")) >> y > [1] "a1" "a10" "a100" "a12" "a2" >> mixedsort(y) > [1] "a1" "a2" "a10" "a12" "a100" > > **Please read the docs!** They say that mixedsort() and mixedorder() both > take a **single vector** as the argument to be sorted or ordered and, as > the above indicates, they perform exactly as advertised. **Unlike > order()**. So of course your do.call() construction fails. > > So presumably you have a data frame with multiple columns of mixed alpha > and numerics? (A reproducible example would be most helpful here.) > > If this is the case, one **possibly dumb** approach (you have been warned!) > would be to turn each column into an ordered factor and then call order() > on the data frame of ordered factors via do.call() as above. i.e. > >> y1 <- ordered(y,lev = mixedsort(y)) >> y1 > [1] a1 a10 a100 a12 a2 > Levels: a1 < a2 < a10 < a12 < a100 >> order(y1) > [1] 1 5 2 4 3 > > (this is just for 1 vector to show how the idea would work). > > Of course, if this is **not** what you want, you'll need to clarify, > hopefully with a reprex. Or hope that someone else has better insight than > I. > > Cheers, > Bert > > > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along and > sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > On Sun, Mar 11, 2018 at 9:15 PM, Sebastien Bihorel < > sebastien.biho...@cognigencorp.com> wrote: > >> Hi, >> >> Searching for functions that would order strings that mix characters and >> numbers in a "natural" way (ie, "a1 a2 a10" instead of "a1 a10 a2"), I >> found the mixedsort and mixedorder from the gtools package. >> >> Problems: >> 1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call >> like the order function does >> 2- gtools has not been updated in 2.5 years >> >> Are you aware of an equivalent of this function in base R or a another >> contributed package (with correction of problem #1)? >> >> Thanks >> >> __ >> 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. > --- Jeff NewmillerThe . . Go Live... DCN:<jdnew...@dcn.davis.ca.us>Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k __ 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] Equivalent of gtools::mixedsort in R base
Hi, Point taken... although this error is not returned in older version of R (3.1.2 does not have any issue with your test case... not sure when the added layer of check was introduced). From: "William Dunlap" <wdun...@tibco.com> To: "Sebastien Bihorel" <sebastien.biho...@cognigencorp.com> Cc: r-help@r-project.org Sent: Monday, March 12, 2018 10:56:43 AM Subject: Re: [R] Equivalent of gtools::mixedsort in R base 1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call like the order function does This is tangential, but do.call(order, mydataframe) is not safe to use in a general purpose function either - you need to remove the names from the second argument: > d <- data.frame(method=c("New","New","Old","Old","Old"), result=5:1) > do.call(order, d) Error in match.arg(method) : 'arg' must be NULL or a character vector > do.call(order, unname(as.list(d))) [1] 2 1 5 4 3 Bill Dunlap TIBCO Software wdunlap [ http://tibco.com/ | tibco.com ] On Sun, Mar 11, 2018 at 9:15 PM, Sebastien Bihorel < [ mailto:sebastien.biho...@cognigencorp.com | sebastien.biho...@cognigencorp.com ] > wrote: Hi, Searching for functions that would order strings that mix characters and numbers in a "natural" way (ie, "a1 a2 a10" instead of "a1 a10 a2"), I found the mixedsort and mixedorder from the gtools package. Problems: 1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call like the order function does 2- gtools has not been updated in 2.5 years Are you aware of an equivalent of this function in base R or a another contributed package (with correction of problem #1)? Thanks __ [ mailto:R-help@r-project.org | R-help@r-project.org ] mailing list -- To UNSUBSCRIBE and more, see [ https://stat.ethz.ch/mailman/listinfo/r-help | https://stat.ethz.ch/mailman/listinfo/r-help ] PLEASE do read the posting guide [ http://www.r-project.org/posting-guide.html | 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.
Re: [R] Equivalent of gtools::mixedsort in R base
So I take this is a no to my initial question. Cheers too. PS: some users just ask questions to get straight answers not to get a solution to their problem :D From: "Bert Gunter" <bgunter.4...@gmail.com> To: "Sebastien Bihorel" <sebastien.biho...@cognigencorp.com> Cc: "R-help" <r-help@r-project.org> Sent: Monday, March 12, 2018 12:57:00 AM Subject: Re: [R] Equivalent of gtools::mixedsort in R base ??? > y <- sort( c("a1","a2","a10","a12","a100")) > y [1] "a1" "a10" "a100" "a12" "a2" > mixedsort(y) [1] "a1" "a2" "a10" "a12" "a100" **Please read the docs!** They say that mixedsort() and mixedorder() both take a **single vector** as the argument to be sorted or ordered and, as the above indicates, they perform exactly as advertised. **Unlike order()**. So of course your do.call() construction fails. So presumably you have a data frame with multiple columns of mixed alpha and numerics? (A reproducible example would be most helpful here.) If this is the case, one **possibly dumb** approach (you have been warned!) would be to turn each column into an ordered factor and then call order() on the data frame of ordered factors via do.call() as above. i.e. > y1 <- ordered(y,lev = mixedsort(y)) > y1 [1] a1 a10 a100 a12 a2 Levels: a1 < a2 < a10 < a12 < a100 > order(y1) [1] 1 5 2 4 3 (this is just for 1 vector to show how the idea would work). Of course, if this is **not** what you want, you'll need to clarify, hopefully with a reprex. Or hope that someone else has better insight than I. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sun, Mar 11, 2018 at 9:15 PM, Sebastien Bihorel < [ mailto:sebastien.biho...@cognigencorp.com | sebastien.biho...@cognigencorp.com ] > wrote: Hi, Searching for functions that would order strings that mix characters and numbers in a "natural" way (ie, "a1 a2 a10" instead of "a1 a10 a2"), I found the mixedsort and mixedorder from the gtools package. Problems: 1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call like the order function does 2- gtools has not been updated in 2.5 years Are you aware of an equivalent of this function in base R or a another contributed package (with correction of problem #1)? Thanks __ [ mailto:R-help@r-project.org | R-help@r-project.org ] mailing list -- To UNSUBSCRIBE and more, see [ https://stat.ethz.ch/mailman/listinfo/r-help | https://stat.ethz.ch/mailman/listinfo/r-help ] PLEASE do read the posting guide [ http://www.r-project.org/posting-guide.html | 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] Equivalent of gtools::mixedsort in R base
Hi, Searching for functions that would order strings that mix characters and numbers in a "natural" way (ie, "a1 a2 a10" instead of "a1 a10 a2"), I found the mixedsort and mixedorder from the gtools package. Problems: 1- mixedorder does not work in a "do.call(mixedorder, mydataframe)" call like the order function does 2- gtools has not been updated in 2.5 years Are you aware of an equivalent of this function in base R or a another contributed package (with correction of problem #1)? Thanks __ 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] Issue of reproducibility with gam and lm.wfit in different versions of R
Dear R users, I recently stumbled upon problems of reproducibility while running GAM analyses in different R and gam package versions. In the example below, a small dataset is created in which the y and x1 variables are 100% correlated. The intents of this example were primarily for regression testing and, secondarily, to evaluate how the gam algorithm behaves under extreme/limit conditions. I ran this little snippet in 5 different environments and got 100% consistent results until I switched to R 3.3.2. * Comparing results from environments 1, 2, and 3 shows that changing the version of the gam package did not change the results under R 3.3.0. * Comparing results from environments 3 and 4 shows that changing the version of R altered the values of the AIC and the output of the step.gam call (changed to a NULL object) * Comparing results from environments 4 and 5 shows that reverting to an older version of the gam package in R 3.3.2 still produced altered AIC values and the NULL output from step.gam call Further investigations into these differences seem to show that the lm.wfit call in the gam.fit function (called from within gam and step.gam) may result in different values in R 3.3.0 and 3.3.2. So my questions are 2-fold: 1- Would you have any information about why lm.wfit would produce different outcomes in R 3.3.0 and 3.3.2? The source code does not appear significantly different. 2- Is it expected that the step.gam function returns a NULL object in R 3.3.2 while a valid model has been identified? Looking at the source of step.gam, the line 157 (if(is.null(form.list)) break) seems to be the reason the function breaks out and returns a NULL value. I thank you in advance for your time. Sebastien Bihorel library(gam) dat <- data.frame( y = c(57,57,98,83,122,69,108,86,80,87,75,76,97,101,121,111,105,84,65,54,61,71,125,60,50,112,102,110,77,45,93,62,120,115,70,113,117,85,46,123,89,95,116,55,110,92,109,100,72,88,105,119,94,45,67,58,60,45,107,73,100,79,47,99,51,53,68,125,90,48,82,85,65,52,70,59,125,49,118,103,91,124,78,81,63,63), x1 = c(52,52,93,78,117,64,103,81,75,82,70,71,92,96,116,106,100,79,60,49,56,66,120,55,45,107,97,105,72,40,88,57,115,110,65,108,112,80,41,118,84,90,111,50,105,87,104,95,67,83,100,114,89,40,62,53,55,40,102,68,95,74,42,94,46,48,63,120,85,43,77,80,60,47,65,54,120,44,113,98,86,119,73,76,58,58), x2 = c(0.0001,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.0001,0) ) summary(dat) scope <- list( x1=c('1','x1','ns(x1, df=2)'), x2=c('1','x2') ) gam.object <- gam(y~1, data=dat) step.object <- step.gam(gam.object, scope=scope, trace=2) is.null(step.object) # Run this if you want to evaluate one lm.wfit example call made from within gam functions x <- cbind(rep(1,nrow(dat)), dat$x1) names(x) <- c('Intercept', 'x1') z <- dat$y w <- rep(1,nrow(dat)) str(eval(expression(lm.wfit(x, z, w, method = "qr", singular.ok = TRUE ## #1 R 3.1.2 (x86_64-redhat-linux-gnu (64-bit)) / gam 1.09.1 ## > step.object <- step.gam(gam.object, scope=scope, trace=2) Start: y ~ 1; AIC= 797.0034 Trial: y ~ x1 + 1 ; AIC= -5121.796 Trial: y ~ 1 + x2 ; AIC= 796.915 Step:1 y ~ x1 ; AIC= -5121.796 Trial: y ~ ns(x1, df=2) + 1 ; AIC= -5123.816 Trial: y ~ x1 + x2 ; AIC= -5174.408 Step:2 y ~ x1 + x2 ; AIC= -5174.408 Trial: y ~ ns(x1, df=2) + x2 ; AIC= -5164.829 > is.null(step.object) [1] FALSE ## #2: R 3.3.0 (x86_64-redhat-linux-gnu (64-bit)) / gam 1.12 ## > step.object <- step.gam(gam.object, scope=scope, trace=2) Start: y ~ 1; AIC= 797.0034 Trial: y ~ x1 + 1 ; AIC= -5121.796 Trial: y ~ 1 + x2 ; AIC= 796.915 Step:1 y ~ x1 ; AIC= -5121.796 Trial: y ~ ns(x1, df=2) + 1 ; AIC= -5123.816 Trial: y ~ x1 + x2 ; AIC= -5174.408 Step:2 y ~ x1 + x2 ; AIC= -5174.408 Trial: y ~ ns(x1, df=2) + x2 ; AIC= -5164.829 > is.null(step.object) [1] FALSE ## #3: R 3.3.0 (x86_64-redhat-linux-gnu (64-bit)) / gam 1.14-4 ## > step.object <- step.gam(gam.object, scope=scope, trace=2) Start: y ~ 1; AIC= 797.0034 Trial: y ~ x1 + 1 ; AIC= -5121.796 Trial: y ~ 1 + x2 ; AIC= 796.915 Step:1 y ~ x1 ; AIC= -5121.796 Trial: y ~ ns(x1, df=2) + 1 ; AIC= -5123.816 Trial: y ~ x1 + x2 ; AIC= -5174.408 Step:2 y ~ x1 + x2 ; AIC= -5174.408 Trial: y ~ ns(x1, df=2) + x2 ; AIC= -5164.829 > is.null(step.object) [1] FALSE ##
[R] Reshaping from long to wide with duplicate idvar and timevar
Hi, I would like to reshape a data.frame from long to wide format. However, the reshape function does not seem to accept data containing rows with duplicate idvar and timevar. Building upon the ?reshape example: summary(Indometh) wide <- reshape(Indometh, v.names = "conc", idvar = "Subject", timevar = "time", direction = "wide") Indometh2 <- rbind(Indometh, Indometh2[1,]) wide <- reshape(Indometh2, v.names = "conc", idvar = "Subject", timevar = "time", direction = "wide") In the 2nd call, reshape drops the duplicate. In a real world, the process I am working on will handle data with unknown number of duplicates like the one I have manually create above. One "brute force" way to circumvent this would be to pre-process the data, identify the rows with duplicate idvar/timevar combos, and add some suffixes to the idvar variable to make the rows unique. Then I would call reshape, and finally, I would post-process the data to remove the suffixes... This does not seem very elegant. Is there a more efficient way to go about this? Thank you __ 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] Vertical boxplot with a continuous X axis
Thanks for your reply - Original Message - From: "Richard M. Heiberger" <r...@temple.edu> To: "Sebastien Bihorel" <sebastien.biho...@cognigencorp.com> Cc: "r-help" <r-help@r-project.org> Sent: Friday, February 24, 2017 1:10:44 AM Subject: Re: [R] Vertical boxplot with a continuous X axis Yes, this is exactly what the panel function panel.bwplot.intermediate.hh along with the position() function in the HH package was designed for. Continuing with the example in the linked stackoverflow df <- structure(list(X1 = c(67.0785968921204, 45.5968692796599, 36.9528452430474, 59.0160838607585, 50.0432724395945, 44.3381091105162, 57.9705240678336, 52.5298724133533, 62.0004216014734, 54.551461596), X2 = c(66.4508598009841, 46.9692156851792, 37.1419457255043, 60.0582991817961, 50.7717368681294, 44.6962314013419, 57.5490276313784, 52.6394305113891, 62.9297233041122, 56.8151766642767), X3 = c(66.4517425831512, 46.2946539468733, 36.5946733567535, 59.2477934854157, 49.1558840130484, 44.7507905380111, 59.1132983272444, 53.710627728232, 61.7923277906642, 57.5999862897015 ), X4 = c(66.1516449763315, 45.4660590159847, 37.2239262718906, 59.2975530712561, 50.2546321578291, 44.722045297, 59.8879656465763, 52.321734919241, 62.0802304973764, 56.6507005349853), X5 = c(66.1810558292955, 46.3301985628267, 36.4487743101244, 60.054119632362, 49.1593136549535, 44.5708909518076, 58.5865142665164, 52.5527273219855, 61.3749185309236, 54.1823379401272), X6 = c(65.9530929286517, 45.5120010675769, 36.7924160587984, 58.9428613519645, 50.3412809263164, 44.9671678827697, 57.8718260182012, 51.8954544252633, 62.0173019998447, 56.3833840769146 ), X7 = c(66.3862581408135, 46.5872469340431, 36.758977493, 58.1374309578563, 50.3399735165261, 44.5739565876491, 57.5245695195136, 52.7613488669329, 61.2500297922529, 55.9202360622414), X8 = c(67.5577910713347, 46.1891742544371, 36.4689522649804, 59.5271358261971, 49.6776114214636, 44.1995317742719, 58.4881363877987, 52.1946266979144, 62.1149998459759, 55.3748655464147), X9 = c(66.3943390258844, 45.843835703738, 37.348512239, 59.8591304277037, 49.387883195468, 44.4283817056918, 58.1874530826789, 53.5091378916001, 62.1187451212786, 55.3632760142297 ), X10 = c(66.9748072219828, 46.20735965374, 36.7069272963502, 59.5035069226904, 48.8446530329762, 44.8753686249692, 58.0223695284058, 53.2732448917674, 61.2509571513, 54.9615424261546), age = c(55, 37, 31, 59, 49, 47, 69, 68, 69, 66)), .Names = c("X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8", "X9", "X10", "age"), row.names = c("GSM1051533_7800246024_R03C02", "GSM1051534_7800246024_R04C02", "GSM1051535_7800246024_R05C02", "GSM1051536_7800246024_R06C02", "GSM1051537_7800246085_R01C01", "GSM1051538_7800246085_R02C01", "GSM1051539_7800246085_R03C01", "GSM1051540_7800246085_R04C01", "GSM1051541_7800246085_R05C01", "GSM1051542_7800246085_R06C01"), class = "data.frame") ## install.packages("HH") ## if necessary library(HH) df.melt <- reshape2::melt(df, id.vars=c("age")) df.melt$age.pos <- factor(df.melt$age) position(df.melt$age.pos) <- levels(df.melt$age.pos) ## three options of x ticks and color bwplot(value ~ age.pos, data=df.melt, horizontal=FALSE, panel=panel.bwplot.intermediate.hh, scales=list( x=list( at=position(df.melt$age.pos), ## placement of tick labels and marks limits=c(29, 71), ## x limits tck=1)), ## draw tick marks xlab="age", main=list("value ~ age", cex=1.4)) bwplot(value ~ age.pos, data=df.melt, horizontal=FALSE, panel=panel.bwplot.intermediate.hh, scales=list( x=list( ## at=position(df.melt$age.pos), ## placement of tick labels and marks limits=c(29, 71), ## x limits tck=1)), ## draw tick marks xlab="age", main=list("value ~ age", cex=1.4)) bwplot(value ~ age.pos, data=df.melt, horizontal=FALSE, panel=panel.bwplot.intermediate.hh, col="blue", ## constant color scales=list( x=list( ## at=position(df.melt$age.pos), ## placement of tick labels and marks limits=c(29, 71), ## x limits tck=1)), ## draw tick marks xlab="age", main=list("value ~ age", cex=1.4)) On Thu, Feb 23, 2017 at 11:52 PM, Sebastien Bihorel <sebastien.biho...@cognigencorp.com> wrote: > > Hi, > > Can the boxplot design illustrated in the post > (http://stackoverflow.com/questions/39849459/how-to-create-boxplo
Re: [R] Vertical boxplot with a continuous X axis
Thanks for your reply - Original Message - From: "Bert Gunter" <bgunter.4...@gmail.com> To: "Sebastien Bihorel" <sebastien.biho...@cognigencorp.com> Cc: "R-help" <r-help@r-project.org> Sent: Friday, February 24, 2017 2:01:36 AM Subject: Re: [R] Vertical boxplot with a continuous X axis Sebastien: The linked post is unclear: two of the rows have the same age, so should there be 10 boxplots for the 10 rows or 9 for the 9 different ages? I assumed the latter, as otherwise how could one disciminate rows with the same age that have overlapping values? For lattice, I just used age as the group= parameter to group by ages and used panel.bwplot for the panel.groups function. My "aesthetics" are different than shown in the linked post, but can be altered in lattice through the panel.bwplot and par.settings parameters as described in ?panel.bwplot: y <- unlist(df[,-11]) age <- rep(df[,"age"],10) ## Could be done programatically xyplot(y~age, groups = age, panel = function(...){ panel.abline(h = seq(40,65, by=5), v = seq(30,70, by =5), col="lightgray") panel.superpose(...) }, panel.groups = function(x,y,...) panel.bwplot(x,y,horiz=FALSE,fill = "lightgray", pch = 16, cex=.7,col= "black",box.width = 1.5), par.settings =list(box.rectangle = list(col="black")) ) However, note that this too could produce a hopeless mishmosh if the ages are close together so that the boxplots overlap; or you could end up getting nearly invisible skinny boxes, as in the plot shown in the linked post. So on the whole, I think you are better off treating the ages as a factor and thereby separating them, e.g. bwplot(y~age, fill = "lightgray", horiz = FALSE, panel = function(...){ panel.abline(h = seq(40,65, by=5),col="lightgray") panel.bwplot(...) }, scales = list(x= list(lab = sort(unique(age, par.settings =list(box.rectangle = list(col="black")) ) Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, Feb 23, 2017 at 8:52 PM, Sebastien Bihorel <sebastien.biho...@cognigencorp.com> wrote: > > Hi, > > Can the boxplot design illustrated in the post > (http://stackoverflow.com/questions/39849459/how-to-create-boxplots-with-a-continuous-x-axis-in-r) > be reproduced with lattice or a lattice-derived function? > > Thank you > > Sebastien > > __ > 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-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] Vertical boxplot with a continuous X axis
Hi, Can the boxplot design illustrated in the post (http://stackoverflow.com/questions/39849459/how-to-create-boxplots-with-a-continuous-x-axis-in-r) be reproduced with lattice or a lattice-derived function? Thank you Sebastien __ 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] Working with Oracle large objects in R
Hi, I was wondering if anybody could share their experience with interfacing R with Oracle databases for extraction of large objects. I would be more specifically interested in how to extract large objects storing big text files. Thank you Sebastien __ 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] Capturing warnings with capture.output
Dear R-users, I would like to follow-up on a old thread by Hadley Wickham about capturing warnings with capture.output. My goal is to evaluate a function call and capture the results of the function call plus warning calls and messages if a warning is returned. For instance, in the following case, I would like to capture the 3 lines of text returned by R log(-1) [1] NaN Warning message: In log(-1) : NaNs produced In Hadley's thread, a combination of capture.output and a custom withWarnings function was proposed to capture warnings but this seems to only capture the warning message and the results of the function call. withWarnings - function(expr) { wHandler - function(w) { cat(w$message, \n) invokeRestart(muffleWarning) } withCallingHandlers(expr, warning = wHandler) } out - capture.output(withWarnings(log(-1))) out [1] NaNs produced [1] NaN In withWarnings, the wHandler function manipulate an object w, which I understand to be a list with a call and message levels. All my attempts to manipulate w$call failed because w$call is of class language. I don't know how to work with this class and I would appreciate any advise on how to process this type of object. Again, the goal is to store both call and message in the output of the withWarnings function. Thank you Sebastien __ 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] Difference of AIC computation between R (2.12) and Splus (7.0.6) during stepwise GAM analysis
Dear R Users, I was wondering if some members of the list could shed some light on the difference in AIC computation existing between R (2.12; gam package) and Splus (7.0.6). Because I am not a statistician by training, I would like to apologize in advance if I use wrong terms or dot not describe GAM appropriately. As far as I understand, stepwise GAM analysis, as implemented in the gam package, relies on the gam, step.gam and gam.fit functions. The computation of AIC, which is used as the primary criterion to advance to the next step, is delegated to the family function provided by the user or set to gaussian by default. If one uses the gaussian default, AIC will be computed as: AIC - aic + 2*(n - fit$df.residual) where: - aic is the results of the function aic - function(y, n, mu, wt, dev) { nobs - length(y) nobs * (log(dev/nobs * 2 * pi) + 1) + 2 - sum(log(wt)) } - y is the vector of observations - n is the number of observations associated in non-null weights - mu is the vector of the fitted values - wt is the vector of weights - dev is the deviance - fit is the object containing fittig information Stepwise GAM analysis, as implemented in Splus, relies on similar but somewhat different gam and step.gam functions. For instance, the computation of AIC does not depend on any family function in Splus. It is hard-coded and performed in the gam.step function and is based upon the formula given by Hastie and Pregibon (Hastie, T. J. and Pregibon, D. (1992) Generalized linear models. Chapter 6 of Statistical Models in S. eds J. M. Chambers and T J. Hastie, Wadsworth Brooks/Cole.): AIC - dev + 2*(n - fit$df.residual)*deviance.lm(fit)/fit$df.resid After running several GAM analysis in R and Splus, there are obvious differences in AIC computation and, thus, final model selection. Overall, this looks to me like R relies on a maximum likelihood estimate of the dispersion, while Splus uses a non-parametric description of the dispersion. Is that right? I look into the help pages but could find something specific on this point. I guess my issue boils down to the following questions: - is there a reference in the literature that would indicate the benefits and inconvenient of the two approaches? - is there a way one can provide arguments to the R gam function so it behaves like the Splus function? Thank you in advance for your feedback and you time. Sebastien __ 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] Global variables
Thanks, I will have a look at it. Sebastien Michael Bedward wrote: Hi Sebastian, You might also find the proto package useful as a way of restricting the scope of variables. It provides a more intuitive (at least to me) way of packaging variables and functions up into environments that can be related in a hierarchy. Michael On 10 January 2011 23:48, Sebastien Bihorel sebastien.biho...@cognigencorp.com wrote: Thank Gabor and Duncan, That will be helpful. Gabor Grothendieck wrote: On Thu, Jan 6, 2011 at 4:59 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 06/01/2011 4:45 PM, Sebastien Bihorel wrote: Dear R-users, Is there a way I can prevent global variables to be visible within my functions? Yes, but you probably shouldn't. You would do it by setting the environment of the function to something that doesn't have the global environment as a parent, or grandparent, etc. The only common examples of that are baseenv() and emptyenv(). For example, x - 1 f - function() print(x) Then f() will work, and print the 1. But if I do environment(f) - baseenv() then it won't work: f() Error in print(x) : object 'x' not found The problem with doing this is that it is not the way users expect functions to work, and it will probably have weird side effects. It is not the way things work in packages (even packages with namespaces will eventually search the global environment, the namespace just comes first). There's no simple way to do it and yet get access to functions in other packages besides base without explicitly specifying them (e.g. you'd need to use stats::lm(), not just lm(), etc.) A variation of this would be: environment(f) - as.environment(2) which would skip over the global environment, .GlobEnv, but would still search the loaded packages. In the example above x would not be found but it still could find lm, etc. [[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. __ 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] Global variables
Thank Gabor and Duncan, That will be helpful. Gabor Grothendieck wrote: On Thu, Jan 6, 2011 at 4:59 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 06/01/2011 4:45 PM, Sebastien Bihorel wrote: Dear R-users, Is there a way I can prevent global variables to be visible within my functions? Yes, but you probably shouldn't. You would do it by setting the environment of the function to something that doesn't have the global environment as a parent, or grandparent, etc. The only common examples of that are baseenv() and emptyenv(). For example, x - 1 f - function() print(x) Then f() will work, and print the 1. But if I do environment(f) - baseenv() then it won't work: f() Error in print(x) : object 'x' not found The problem with doing this is that it is not the way users expect functions to work, and it will probably have weird side effects. It is not the way things work in packages (even packages with namespaces will eventually search the global environment, the namespace just comes first). There's no simple way to do it and yet get access to functions in other packages besides base without explicitly specifying them (e.g. you'd need to use stats::lm(), not just lm(), etc.) A variation of this would be: environment(f) - as.environment(2) which would skip over the global environment, .GlobEnv, but would still search the loaded packages. In the example above x would not be found but it still could find lm, etc. [[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] Stop and call objects
Well, the goal is to include a reference to f2 in the error message returned by f2('char'); sys.call(1) appears to do the trick. You mentioned this function could be unreliable, could you please provide an example? Sebastien William Dunlap wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Henrique Dallazuanna Sent: Wednesday, January 05, 2011 9:26 AM To: Sebastien Bihorel Cc: R-help Subject: Re: [R] Stop and call objects Try this: f - function(x) tryCatch(sum(x),error=function(e)sprintf(Error in %s: %s, deparse(sys.call(1)), e$message)) f('a') The argument e to the error handler contains a call component so you don't have to rely on the unreliable sys.call(1) to get the offending call. E.g., f2 - function(x) { tryCatch(sum(x), error=function(e) { sprintf(Error in %s: %s, deparse(e$call)[1], e$message) } ) } f2('char') [1] Error in sum(x): invalid 'type' (character) of argument Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com On Wed, Jan 5, 2011 at 12:23 PM, Sebastien Bihorel sebastien.biho...@cognigencorp.com wrote: Dear R-users, Let's consider the following snippet: f - function(x) tryCatch(sum(x),error=function(e) stop(e)) f('a') As expected, the last call returns an error message: Error in sum(x) : invalid 'type' (character) of argument My questions are the following: 1- can I easily ask the stop function to reference the f function in addition to sum(x) in the error message? 2- If not, I guess I would have to extract the call and message objects from e, coerce the call as a character object, build a custom string, and pass it to the stop function using call.=F. How can I coerce a call object to a character and maintain the aspect of the printed call (i.e. sum(x) instead of the character vector sum x returned by as.character(e$call))? Thank you Sebastien __ 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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] [[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.
[R] Global variables
Dear R-users, Is there a way I can prevent global variables to be visible within my functions? Sebastien __ 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] Stop and call objects
Dear R-users, Let's consider the following snippet: f - function(x) tryCatch(sum(x),error=function(e) stop(e)) f('a') As expected, the last call returns an error message: Error in sum(x) : invalid 'type' (character) of argument My questions are the following: 1- can I easily ask the stop function to reference the f function in addition to sum(x) in the error message? 2- If not, I guess I would have to extract the call and message objects from e, coerce the call as a character object, build a custom string, and pass it to the stop function using call.=F. How can I coerce a call object to a character and maintain the aspect of the printed call (i.e. sum(x) instead of the character vector sum x returned by as.character(e$call))? Thank you Sebastien __ 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] R command execution from shell
Thank you for this alternative. Both seem to work on my systems. Sebastien Prof Brian Ripley wrote: On Tue, 4 Jan 2011, Duncan Murdoch wrote: On 04/01/2011 3:21 PM, Sebastien Bihorel wrote: Dear R-users, Is there a way I can ask R to execute the write(hello world,file=hello.txt) command directly from the UNIX shell, instead of having to save this command to a .R file and execute this file with R CMD BATCH? Yes. Some versions of R support the -e option on the command line to execute a particular command. It's not always easy to work out the escapes so your shell passes all the quotes through... An alternative is to echo the command into the shell, e.g. echo 'cat(hello)' | R --slave (where the outer ' ' are just for bash). It is marginally preferable to use Rscript in place of 'R --slave'. I think in all known shells Rscript -e write('hello world', file = 'hello.txt') will work. (If not, shQuote() will not work for that shell, but this does work in sh+clones, csh+clones, zsh and Windows' cmd.exe.) __ 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] R command execution from shell
Dear R-users, Is there a way I can ask R to execute the write(hello world,file=hello.txt) command directly from the UNIX shell, instead of having to save this command to a .R file and execute this file with R CMD BATCH? Thank you Sebastien __ 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] R command execution from shell
Thank you That is exactly what I was looking for. Sebastien Duncan Murdoch wrote: On 04/01/2011 3:21 PM, Sebastien Bihorel wrote: Dear R-users, Is there a way I can ask R to execute the write(hello world,file=hello.txt) command directly from the UNIX shell, instead of having to save this command to a .R file and execute this file with R CMD BATCH? Yes. Some versions of R support the -e option on the command line to execute a particular command. It's not always easy to work out the escapes so your shell passes all the quotes through... An alternative is to echo the command into the shell, e.g. echo 'cat(hello)' | R --slave (where the outer ' ' are just for bash). Duncan Murdoch __ 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] [R-pkgs] Release of the scaRabee package
Dear R-users, I am pleased to announce the release of scaRabee, a new R package which constitutes a toolkit for modeling and simulation in the field of pharmacometrics. It was designed as a user-friendly interface to create and modify model scripts, define system observations and inputs, and run simulation or estimation analysis. scaRabee provides templates for the definition of pharmacokinetic-pharmacodynamic models with closed form solutions, ordinary or delay differential equations. At the end of each analysis, scaRabee automatically generates diagnostic plots, report files with run estimate statistics, and a log file with the history of the optimization process (for estimation runs). Optimization in scaRabee are performed using the simplex method of Nelder and Mead, implemented in the neldermead package. scaRabee is available on CRAN or at http://code.google.com/p/pmlab/ in version 1.0. Any question, comment or feedback on this package is to be sent at: sb.pm...@gmail.com. Sebastien Bihorel [[alternative HTML version deleted]] ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ 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] [R-pkgs] Release of optimbase, optimsimplex and neldermead packages
Dear R users, I am pleased to announce the release of three new R packages: optimbase, optimsimplex, and neldermead. - optimbase provides a set of commands to manage an abstract optimization method. The goal is to provide a building block for a large class of specialized optimization methods. This package manages: the number of variables, the minimum and maximum bounds, the number of non linear inequality constraints, the cost function, the logging system, various termination criteria, etc... - optimsimplex provides a building block for optimization algorithms based on a simplex. The optimsimplex package may be used in the following optimization methods: the simplex method of Spendley et al., the method of Nelder and Mead, Box's algorithm for constrained optimization, the multi-dimensional search by Torczon, etc... - neldermead depends on optimbase and optimsimplex and provides several direct search optimization algorithms based on the simplex method. The provided algorithms are direct search algorithms, i.e. algorithms which do not use the derivative of the cost function. They are based on the update of a simplex. The following algorithms are available: the fixed size simplex method of Spendley, Hext and Himsworth (unconstrained optimization with a fixed sized simplex), the variable size simplex method of Nelder and Mead (unconstrained optimization with a variable sized simplex), Box's complex method (constrained optimization with a variable sized simplex). This package includes an R-port of the fminsearch function (available in Matlab and Scilab) which is a specialized use of the more general neldermead package and computes the unconstrained minimimum of given function with the Nelder-Mead algorithm. One important benefit offered by those packages (especially optimbase) is the possibly for the user to define functions that will be called at the each iteration of the optimization process. These functions may be used when debugging a specialized optimization algorithm, to write to one or several report files, or create/update optimization graphs. optimbase can accommodate both derivative-based or derivative-free algorithms. The three packages are ports of original Scilab modules written by Michael Baudin at the Digiteo Consortium (and previously at Institut National de Recheche en Informatique et en Automatique). All packages are available in version 1.0-1 on CRAN. Any question, comment or feedback on those packages can be sent at: sb.pm...@gmail.com. Sebastien Bihorel [[alternative HTML version deleted]] ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ 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] Adjust lattice graph axis label on final page
Thanks Deepayan, This confirms what I thought I should do... One follow-up question about your suggested code: is it possible to create a lattice graph object myplot and modify the layout just for panel 7 and 8, rather than creating two graphs with different layouts? Sebastien Deepayan Sarkar wrote: On Thu, Feb 25, 2010 at 3:45 AM, Sebastien Bihorel sebastien.biho...@cognigencorp.com wrote: Dear R-users, I was wondering if there was a way to adjust the placement of the axis titles for the last page of a multi-page lattice plot (see example below). Depending on the total number of panels, the placement of these titles might look strange on the last page, if the layout is not adjusted (e.g. in some template code). It's not possible to adjust the labels on a per-page basis. It _is_ possible to have the two plots fill up the last page, but that may not be what you want. xyplot(y~x|id,as.table=T,data=mydata,layout=c(2,3))[1:6] xyplot(y~x|id,as.table=T,data=mydata,layout=c(2,1))[7:8] -Deepayan __ 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] Adjust lattice graph axis label on final page
Dear R-users, I was wondering if there was a way to adjust the placement of the axis titles for the last page of a multi-page lattice plot (see example below). Depending on the total number of panels, the placement of these titles might look strange on the last page, if the layout is not adjusted (e.g. in some template code). Any thought on this issue would be welcome. Sebastien library(lattice) mydata - data.frame(x=rep(1:10,8), y=rep(1:10,8), id=rep(1:8,each=10)) xyplot(y~x|id,as.table=T,data=mydata,layout=c(2,3)) __ 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] Passing arguments to gpar
Hi, Yes, that is exactly it. Charlie Sharpsteen gave me the same solution last week but he probably just replied to me, so his email did not go to the list. Thanks for the reply, I appreciate it I always forget about this do.call function. Paul Murrell wrote: Hi Sebastien Bihorel wrote: Dear R-users, I would like to know how to pass arguments to gpar() without hard-coding them. I tried to store my arguments in a list and passed this list to gpar(), but it did find the way to do it properly. Any help would be appreciated. a- list(fontisze=8,col=3) gpar(fontsize=8,col=3) gpar(a) gpar(unlist(a)) Are you looking for this ... ? do.call(gpar, a) Paul __ 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-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] Source code for some grid package documentation
Dear R-users, I was wondering if anybody would have the source code used to create the last figure in the frame.pdf documentation distributed with the grid package. Thanks in advance. __ 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] Source code for some grid package documentation
Thank you Romain, I appreciate the help. Romain Francois wrote: On 12/04/2009 04:28 PM, Sebastien Bihorel wrote: Dear R-users, I was wondering if anybody would have the source code used to create the last figure in the frame.pdf documentation distributed with the grid package. file.show( vignette( frame, package = grid )$file ) Thanks in advance. __ 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] Apparent different in symbol scaling between xyplot and grid.points
Dear R-users, For the past few days, I have been trying to find the reason why some of my plots were showing symbols of different sizes, while I thought I was using the same .cex arguments everywhere. The problem is exemplified by the following example code where the xyplot and grid.points functions are used. The scaling factor is set to 0.84 in both the functions settings, but one can see that, in the pdf file, the blue symbols plotted by xyplot are smaller than the single black symbol created by grid.points. Playing with the trellis settings did not seem to solve the problem. I am missing a hidden scaling factor somewhere, but don't know where to look anymore I would greatly appreciate the feedback of the list on this issue. library(lattice) library(grid) pdf(file=test.pdf) df - data.frame(a=1:12,b=1:12,c=rep(1:4,each=3)) #trellis.par.set(superpose.symbol=list(cex=1)) xyplot(b~a|c, data=df, panel = function(x,y){ panel.xyplot(x,y,pch=3,cex=0.84)} ) str(trellis.par.get()) str(get.gpar()) grid.points(x=100,y=85,pch=3,gp=gpar(cex=0.84)) dev.off() __ 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] Apparent different in symbol scaling between xyplot and grid.points
Thanks Baptiste, I think you nailed it. baptiste auguie wrote: Hi, I think the size mismatch occurs because of a different default for the fontsize (and grid.points has a size of 1 character by default). Compare the following two examples, # default grid.newpage() pushViewport(viewport(x=unit(0.5, npc), y=unit(0.5, npc))) lplot.xy(data.frame(x=0.55,y=0.5),type=p, pch=3) grid.points(x=0.45,y=0.5, pch=3, gp=gpar(col=red)) trellis.par.set(fontsize, list(points=12)) grid.newpage() pushViewport(viewport(x=unit(0.5, npc), y=unit(0.5, npc))) lplot.xy(data.frame(x=0.55,y=0.5),type=p, pch=3) grid.points(x=0.45,y=0.5, pch=3, gp=gpar(col=red)) HTH, baptiste 2009/12/4 Sebastien Bihorel sebastien.biho...@cognigencorp.com: Dear R-users, For the past few days, I have been trying to find the reason why some of my plots were showing symbols of different sizes, while I thought I was using the same .cex arguments everywhere. The problem is exemplified by the following example code where the xyplot and grid.points functions are used. The scaling factor is set to 0.84 in both the functions settings, but one can see that, in the pdf file, the blue symbols plotted by xyplot are smaller than the single black symbol created by grid.points. Playing with the trellis settings did not seem to solve the problem. I am missing a hidden scaling factor somewhere, but don't know where to look anymore I would greatly appreciate the feedback of the list on this issue. library(lattice) library(grid) pdf(file=test.pdf) df - data.frame(a=1:12,b=1:12,c=rep(1:4,each=3)) #trellis.par.set(superpose.symbol=list(cex=1)) xyplot(b~a|c, data=df, panel = function(x,y){ panel.xyplot(x,y,pch=3,cex=0.84)} ) str(trellis.par.get()) str(get.gpar()) grid.points(x=100,y=85,pch=3,gp=gpar(cex=0.84)) dev.off() __ 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-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] Passing arguments to gpar
Dear R-users, I would like to know how to pass arguments to gpar() without hard-coding them. I tried to store my arguments in a list and passed this list to gpar(), but it did find the way to do it properly. Any help would be appreciated. a- list(fontisze=8,col=3) gpar(fontsize=8,col=3) gpar(a) gpar(unlist(a)) __ 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] How to concatenate expressions
Dear R-users, I am developing a plotting function, which receives expressions and character/numerical vectors as part of the many input arguments and which tries to concatenate them before displaying the result to the plot. I currently cannot find a way to make this concatenation works. I have read several posts in the list that solved this problem by pasting the different elements together before creating the expressions (like in http://tolstoy.newcastle.edu.au/R/help/02a/4790.html). I cannot implement this solution because my expressions and numerical/character vectors are passed to the function and not create inside the function. I would greatly appreciate any help with the following example code. Thank you testplot - function(a,b,c) { text - as.expression(paste(a,b,c,sep=' ')) dev.new() plot(-5:5,-5:5,col=0) for (i in 1:3) { text(x=i, y=i, labels=text[i]) } } a - as.expression(c(bquote(alpha),bquote(beta),bquote(gamma))) b - as.expression(1:3) c - as.expression(c(bquote('-10'^th), bquote('-20'^th), bquote('-30'^th))) testplot(a,b,c) __ 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] How to concatenate expressions
Thanks a bunch, Baptiste, Your lapply call works like a charm. BTW, it works also if a, b, and c are expressions :D Sebastien baptiste auguie wrote: Hi, You can try this, though I hope to learn of a better way to do it, a = c(quote(alpha),quote(beta),quote(gamma)) b = lapply(1:3, function(x) as.character(x)) c = c(quote('-10'^th), quote('-20'^th), quote('-30'^th)) testplot - function(a,b,c) { text - lapply(seq_along(a), function(ii) bquote(.(a[[ii]])*.(b[[ii]])*.(c[[ii]]))) dev.new() plot(-5:5,-5:5,col=0) for (i in seq_along(a)) { text(x=i, y=i, labels=text[[i]]) } } testplot(a,b,c) HTH, baptiste 2009/11/20 Sebastien Bihorel sebastien.biho...@cognigencorp.com: Dear R-users, I am developing a plotting function, which receives expressions and character/numerical vectors as part of the many input arguments and which tries to concatenate them before displaying the result to the plot. I currently cannot find a way to make this concatenation works. I have read several posts in the list that solved this problem by pasting the different elements together before creating the expressions (like in http://tolstoy.newcastle.edu.au/R/help/02a/4790.html). I cannot implement this solution because my expressions and numerical/character vectors are passed to the function and not create inside the function. I would greatly appreciate any help with the following example code. Thank you testplot - function(a,b,c) { text - as.expression(paste(a,b,c,sep=' ')) dev.new() plot(-5:5,-5:5,col=0) for (i in 1:3) { text(x=i, y=i, labels=text[i]) } } a - as.expression(c(bquote(alpha),bquote(beta),bquote(gamma))) b - as.expression(1:3) c - as.expression(c(bquote('-10'^th), bquote('-20'^th), bquote('-30'^th))) testplot(a,b,c) __ 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-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] Code improvement
Hi Baptisti, Sorry for the late reply. I wanted to thank you for putting me on the right track. I finally got something to work not really by extracting the legend from a xyplot call, but by building my own legend grid.frame and passing it to my low-level function. Understanding Grobs and grid.pack took me some time, but now, it is working like a charm. Thank again to you (and to Paul Murrell for the grid package!) Sebastien baptiste auguie wrote: Hi, I don't know if it helps, but looking at the output of xyplot you can extract the legend (a grid.frame) as follows, library(grid) library(lattice) p = xyplot(x~y, group=x,data=data.frame(x=1:10,y=1:10), auto.key=list(space=right)) legend = with(p$legend$right, do.call(lattice:::drawSimpleKey, args)) grid.draw(legend) and lattice::draw.key might also help if you need to customize the legend. HTH, baptiste 2009/10/22 Sebastien Bihorel sebastien.biho...@cognigencorp.com: Dear R-Users, I would like to have the opinion of the list on the following matter. I have this generic function that creates multiple lattice scatterplots per page based upon different subsets of the same dataset. The use of different line/point colors/symbols in each plot is based upon a 'group' variable', which is the same for all plots. My goal is to create a main legend per page: 1- because the 'group' variable' is the same for all plots, one legend per page is sufficient; 2- because the subset of data used for a particular scatterplot does not have to contain all unique elements of the group variable in the whole dataset, the graphical settings need to be adjusted for each plot based upon a general list of settings created from the whole dataset prior to the creation of the plots; 3- for the same reason, I cannot use the key argument of xyplot to create a legend from the first scatterplot. Another piece of info is that this generic function could be used to create very different categories of graphs, which each require a different legend design. At the moment, I am creating the legend based upon the general graph settings and the category of plot. Prior to the creation of the graphs, I store grid objects (text, point, line, or rectangle) into a list, with also some information about the number of lines that the legend will use, and the category of the plot. After the plots are printed to the device, I open a viewport at the bottom of my page and split it according to the type of the graph and the number of lines it needs. Finally, I just loop through the content of the list and draw the grid objects. Overall, this is all fine but a bit 'brute force'. Also the final 'open-a-viewport-and-draw-inside' step is a big messy code within a generic graph function, because one specific piece of code is needed per category of plot, and because of additional subtleties (conditional argument, etc... ) Based upon the behavior of the xyplot function, I understand that it would be possible to store the fully formatted legend directly at its creation and then just 'print' the stored object within my legend viewport. Could anybody advise me on the process to follow to accomplish that or maybe a few functions to look at? As always, any help would be greatly appreciated. Sebastien __ 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-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] Code improvement
Dear R-Users, I would like to have the opinion of the list on the following matter. I have this generic function that creates multiple lattice scatterplots per page based upon different subsets of the same dataset. The use of different line/point colors/symbols in each plot is based upon a 'group' variable', which is the same for all plots. My goal is to create a main legend per page: 1- because the 'group' variable' is the same for all plots, one legend per page is sufficient; 2- because the subset of data used for a particular scatterplot does not have to contain all unique elements of the group variable in the whole dataset, the graphical settings need to be adjusted for each plot based upon a general list of settings created from the whole dataset prior to the creation of the plots; 3- for the same reason, I cannot use the key argument of xyplot to create a legend from the first scatterplot. Another piece of info is that this generic function could be used to create very different categories of graphs, which each require a different legend design. At the moment, I am creating the legend based upon the general graph settings and the category of plot. Prior to the creation of the graphs, I store grid objects (text, point, line, or rectangle) into a list, with also some information about the number of lines that the legend will use, and the category of the plot. After the plots are printed to the device, I open a viewport at the bottom of my page and split it according to the type of the graph and the number of lines it needs. Finally, I just loop through the content of the list and draw the grid objects. Overall, this is all fine but a bit 'brute force'. Also the final 'open-a-viewport-and-draw-inside' step is a big messy code within a generic graph function, because one specific piece of code is needed per category of plot, and because of additional subtleties (conditional argument, etc... ) Based upon the behavior of the xyplot function, I understand that it would be possible to store the fully formatted legend directly at its creation and then just 'print' the stored object within my legend viewport. Could anybody advise me on the process to follow to accomplish that or maybe a few functions to look at? As always, any help would be greatly appreciated. Sebastien __ 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] How to calculate the area under the curve
Well, you can use the trapezoidal rule to numerically calculate any area under the curve. I don't know if a specific exists but you could create one. The principle is basically to compute the area between two successive points of your profile with: AREA=0.5*(Response1 + Response2)/(Time2-Time1) where time1 and time2 are the time of response1 and response2. You will finally add all the areas together to obtain the total area between your first and last point. HIH Hi all, I would like to calculate the area under the ROC curve for my predictive model. I have managed to plot points giving me the ROC curve. However, I do not know how to get the value of the area under. Does anybody know of a function that would give the result I want using an array of specificity and an array of sensitivity as input? Thanks, Olivier __ 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] Regular expression problem
Dear R-users, I am trying to use the grep function to test whether a particular string is of the form n.../mydir/myfile.mytype.myext. Anything between n and mytype could vary, and anything after mytype could vary. I tried to proceed by steps to build my regular expression... but I do not really understand why the last call of the following code do not work. Any help would be greatly appreciated. mystr - n.../mydir/myfile.mytype.myext grep(mytype,mystr) # returns 1 grep([.]*mytype,mystr) # returns 1 grep(n[.]*mytype,mystr) # returns integer(0) Sebastien __ 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] Regular expression problem
Thanks Jim and Rolf, grep(n.*mytype,mystr) will do. I thought that * only applies on group of characters defined in a [] sequence. Would you be aware of any documentation/tutorial that would give slightly more detail and examples that the ?regexp? Also, would you be aware of any (online) tool to test R-style regular expression against some text or strings? On 16/09/2009, at 9:58 AM, jim holtman wrote: try: grep(n.*mytype,mystr) [1] 1 with the [.] it is a class with a period. '.*' match zero, or more, characters. Perhaps the OP wants grep(n[.].*mytype,mystr) to insist that ``mystr'' contain the string ``n.'' (literal ``.'') somewhere before the string ``mytype''. cheers, Rolf Turner On Tue, Sep 15, 2009 at 5:52 PM, Sebastien Bihorel sebastien.biho...@cognigencorp.com wrote: Dear R-users, I am trying to use the grep function to test whether a particular string is of the form n.../mydir/myfile.mytype.myext. Anything between n and mytype could vary, and anything after mytype could vary. I tried to proceed by steps to build my regular expression... but I do not really understand why the last call of the following code do not work. Any help would be greatly appreciated. mystr - n.../mydir/myfile.mytype.myext grep(mytype,mystr) # returns 1 grep([.]*mytype,mystr) # returns 1 grep(n[.]*mytype,mystr) # returns integer(0) Sebastien __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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. ## Attention: This e-mail message is privileged and confidential. If you are not the intended recipient please delete the message and notify the sender. Any views or opinions presented are solely those of the author. This e-mail has been scanned and cleared by MailMarshal www.marshalsoftware.com ## __ 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] combining grid.text, expression and variables
Dear R-users, I am trying to use the grid.text and expression functions to display several character strings and plotmath text on a viewport. Some strings can include a variable portion (PI.limits in the following example), which I thought could be implemented by combining the bquote and the expression functions. Unfortunately, my expressions do not seem to be evaluated. I would greatly appreciate if somebody could tell me where my mistake(s) is(are). Thank you in advance ## 8 ### library(grid) PI.limits - c(0.1,0.9) vp.ref - c(raw data,median,median, bquote(expression(paste(.(PI.limits[1]*100), and , .(PI.limits[2]*100)^th, percentiles, sep=))), bquote(expression(paste(95^th,confidence interval on percentiles, sep= ))), bquote(expression(paste(95^th,confidence interval on percentiles, sep= ))) ) grid.newpage() for (i in c(1,3,4,5,6)) { grid.text(eval(vp.ref[i]), x=0.5, y=unit(1,npc)-unit(i,lines)) } __ 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] combining grid.text, expression and variables
Hi Baptiste, Thank for the help. One thing though that I found while transposing your syntax to my problem: lab must be of class expression for your syntax to work. For instance, if one replaces the second elements of the lab variables by a simple integer, lab is not more of class expression, and grid.text just displays strings of character. An easy way to bullet proof the code: use as.expression when building lab Thanks baptiste auguie wrote: Hi, Try this, library(grid) value - c(0.1) lab - c(test, expression(bquote(paste(.(value[1]*100), and percentiles1, sep=))), bquote(expression(.(value[1]*100)* and percentiles2)), bquote(paste(.(value[1]*100), and percentiles3, sep=)) ) grid.newpage() grid.text(eval(lab[1]), x=0.5, y=unit(1,npc)-unit(1,lines)) grid.text(eval(lab[2]), x=0.5, y=unit(1,npc)-unit(2,lines)) grid.text(eval(lab[3]), x=0.5, y=unit(1,npc)-unit(3,lines)) grid.text(lab[4], x=0.5, y=unit(1,npc)-unit(4,lines)) My preference goes for the last one. HTH, baptiste 2009/9/2 Sebastien Bihorel sebastien.biho...@cognigencorp.com mailto:sebastien.biho...@cognigencorp.com Dear R-users, I am trying to use the grid.text and expression functions to display several character strings and plotmath text on a viewport. Some strings can include a variable portion (PI.limits in the following example), which I thought could be implemented by combining the bquote and the expression functions. Unfortunately, my expressions do not seem to be evaluated. I would greatly appreciate if somebody could tell me where my mistake(s) is(are). Thank you in advance ## 8 ### library(grid) PI.limits - c(0.1,0.9) vp.ref - c(raw data,median,median, bquote(expression(paste(.(PI.limits[1]*100), and , .(PI.limits[2]*100)^th, percentiles, sep=))), bquote(expression(paste(95^th,confidence interval on percentiles, sep= ))), bquote(expression(paste(95^th,confidence interval on percentiles, sep= ))) ) grid.newpage() for (i in c(1,3,4,5,6)) { grid.text(eval(vp.ref[i]), x=0.5, y=unit(1,npc)-unit(i,lines)) } __ R-help@r-project.org mailto: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. -- _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK http://newton.ex.ac.uk/research/emag __ __ 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] Problem with passing a string to subset
Thanks Baptiste The eval(parse()) combination is just what I need. baptiste auguie wrote: Try this, mystr -c==1 subset(foo, eval(parse(text = mystr)) ) library(fortunes) fortune(parse) # try several times # I prefer this, but there is probably a better way mycond- quote(c==1) subset(foo, eval(bquote(.(mycond))) ) HTH, baptiste 2009/8/21 Sebastien Bihorel sebastien.biho...@cognigencorp.com: Dear R-users, The following question bothered me for the whole afternoon: how can one pass a string as the conditioning argument to subset? I tried plain mystr, eval(mystr), expression(mystr), etc... I don't to be able to find the correct syntax foo - data.frame(a=1:10,b=10:1,c=rep(1:2,5)) mystr-c==1 subset(foo,c==1) a b c 1 1 10 1 3 3 8 1 5 5 6 1 7 7 4 1 9 9 2 1 subset(foo,mystr) Error in subset.data.frame(foo, mystr) : 'subset' must evaluate to logical Any help would be greatly appreciated. Sebastien __ 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-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] Problem with passing a string to subset
Dear R-users, The following question bothered me for the whole afternoon: how can one pass a string as the conditioning argument to subset? I tried plain mystr, eval(mystr), expression(mystr), etc... I don't to be able to find the correct syntax foo - data.frame(a=1:10,b=10:1,c=rep(1:2,5)) mystr-c==1 subset(foo,c==1) a b c 1 1 10 1 3 3 8 1 5 5 6 1 7 7 4 1 9 9 2 1 subset(foo,mystr) Error in subset.data.frame(foo, mystr) : 'subset' must evaluate to logical Any help would be greatly appreciated. Sebastien __ 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] Passing expression as argument to do.call
Dear R-users, I would like to know how expressions could be passed as arguments to do.call functions. As illustrated in the short example below, concatenating lists objects and an expression creates an expression object, which is not an acceptable argument for do.call. Is there a way to avoid that? Thanks you Sebastien foo - list(x=1:10, y=1:10) mylist - list(pch=6, col=2) title - 1 microgram title2 - expression (1 mu g) do.call(plot, c(foo, mylist, main=title)) class(c(foo, mylist, main=title2)) do.call(plot, c(foo, mylist, main=title2)) __ 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] Passing expression as argument to do.call
Damned, I did tried as.list but not list... Thanks Hadley and Duncan for your quick replies On Thu, Jul 2, 2009 at 3:34 PM, Sebastien Bihorelsebastien.biho...@cognigencorp.com wrote: Dear R-users, I would like to know how expressions could be passed as arguments to do.call functions. As illustrated in the short example below, concatenating lists objects and an expression creates an expression object, which is not an acceptable argument for do.call. Is there a way to avoid that? Thanks you Sebastien foo - list(x=1:10, y=1:10) mylist - list(pch=6, col=2) title - 1 microgram title2 - expression (1 mu g) do.call(plot, c(foo, mylist, main=title)) class(c(foo, mylist, main=title2)) do.call(plot, c(foo, mylist, main=title2)) do.call(plot, c(foo, mylist, list(main=title2))) Both foo and myllist are already lists, but title2 isn't. Hadley -- http://had.co.nz/ __ 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] lattice strip argument check
Dear R-Users, Is there a way to check within the following dummy function if the strip argument is different from the default set in the function declaration? FYI, this argument should be used downstream in a xyplot call of my actual function. dummyfunction - function(..., strip = function(...) strip.default(...,strip.names=c(TRUE,TRUE))) {} Thanks for your help -- *Sebastien Bihorel, PharmD, PhD* PKPD Scientist Cognigen Corp Email: sebastien.biho...@cognigencorp.com mailto:sebastien.biho...@cognigencorp.com Phone: (716) 633-3463 ext. 323 __ 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] Problem with viewports, print.trellis and more/newpage
Hi Deepayan, Thank you very much for the tip. After removing the 'more' argument and another couple of hours, I finally found something that works for my multi-page multi-graph plots. For documentation, the script is: library(lattice) library(grid) foo - data.frame(x=1:10,y=1:10) # Defines some viewports fulldevice - viewport(x=0, y=0, width=1, height=1, just=c(0,0), name=fulldevice) plotvw - viewport(x=0, y=0, width=1, height=0.95, just=c(0,0), name=plotvw) titlevw - viewport(x=0, y=0.95, width=1, height=0.05, just=c(0,0), name=titlevw) tree - vpTree(fulldevice,vpList(plotvw,titlevw)) for (i in 1:4) { plots - xyplot((i*y)~x,data=foo) grid.newpage() pushViewport(tree) seekViewport(plotvw) print(plots, split=c(1,1,2,4), newpage=FALSE) print(plots, split=c(2,1,2,4), newpage=FALSE) print(plots, split=c(1,2,2,4), newpage=FALSE) print(plots, split=c(2,2,2,4), newpage=FALSE) print(plots, split=c(1,3,2,4), newpage=FALSE) print(plots, split=c(2,3,2,4), newpage=FALSE) print(plots, split=c(1,4,2,4), newpage=FALSE) print(plots, split=c(2,4,2,4), newpage=FALSE) seekViewport(titlevw) grid.text(label = test, just = c(centre,centre), gp = gpar(fontsize = 10, font = 2)) } On Thu, May 14, 2009 at 1:58 PM, Sebastien Bihorel sebastien.biho...@cognigencorp.com wrote: Dear R-users, I have got the following problem. I need to create 4x2 arrays of xyplot's on several pages. The plots are created within a loop and plotted using the print function. It seems that I cannot find the proper grid syntax with my viewports, and the more/newpage arguments. The following script is a simplification but hopefully will suffice to illustrate my problem. Any suggestion from the list would be greatly appreciated. Without looking at it in detail, here's one bit of advice that might help: if you are using pushViewport(), don't use 'more', use only 'newpage', and preferably don't use 'split' either. In particular, if you are using 'more', the first print.trellis() call will always start a new page, and your viewport will be lost. -Deepayan Sebastien # library(lattice) foo - data.frame(x=1:10,y=1:10) for (i in 1:4) {  #isnewpage -   FALSE  plots - xyplot(y~x,data=foo)  pushViewport(viewport(x=0,            y=0,            width=1,            height=0.95,            just=c(0,0)))  print(plots, split=c(1,1,2,4), more=T)#, newpage=isnewpage)  print(plots, split=c(2,1,2,4), more=T)#, newpage=isnewpage)  print(plots, split=c(1,2,2,4), more=T)#, newpage=isnewpage)  print(plots, split=c(2,2,2,4), more=T)#, newpage=isnewpage)  print(plots, split=c(1,3,2,4), more=T)#, newpage=isnewpage)  print(plots, split=c(2,3,2,4), more=T)#, newpage=isnewpage)  print(plots, split=c(1,4,2,4), more=T)#, newpage=isnewpage)  print(plots, split=c(2,4,2,4), more=F)#, newpage=isnewpage)    popViewport()    pushViewport(viewport(x=0,            y=0.95,            width=1,            height=0.05,            just=c(0,0)))   grid.text(label = i,        just = c(centre,centre),        gp = gpar(fontsize = 10, font = 2))   popViewport()    # Updates isnewpage  # isnewpage - TRUE } -- *Sebastien Bihorel, PharmD, PhD* PKPD Scientist Cognigen Corp Email: sebastien.biho...@cognigencorp.com mailto:sebastien.biho...@cognigencorp.com Phone: (716) 633-3463 ext. 323 __ 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-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] Problem with viewports, print.trellis and more/newpage
Dear R-users, I have got the following problem. I need to create 4x2 arrays of xyplot's on several pages. The plots are created within a loop and plotted using the print function. It seems that I cannot find the proper grid syntax with my viewports, and the more/newpage arguments. The following script is a simplification but hopefully will suffice to illustrate my problem. Any suggestion from the list would be greatly appreciated. Sebastien # library(lattice) foo - data.frame(x=1:10,y=1:10) for (i in 1:4) { #isnewpage - FALSE plots - xyplot(y~x,data=foo) pushViewport(viewport(x=0, y=0, width=1, height=0.95, just=c(0,0))) print(plots, split=c(1,1,2,4), more=T)#, newpage=isnewpage) print(plots, split=c(2,1,2,4), more=T)#, newpage=isnewpage) print(plots, split=c(1,2,2,4), more=T)#, newpage=isnewpage) print(plots, split=c(2,2,2,4), more=T)#, newpage=isnewpage) print(plots, split=c(1,3,2,4), more=T)#, newpage=isnewpage) print(plots, split=c(2,3,2,4), more=T)#, newpage=isnewpage) print(plots, split=c(1,4,2,4), more=T)#, newpage=isnewpage) print(plots, split=c(2,4,2,4), more=F)#, newpage=isnewpage) popViewport() pushViewport(viewport(x=0, y=0.95, width=1, height=0.05, just=c(0,0))) grid.text(label = i, just = c(centre,centre), gp = gpar(fontsize = 10, font = 2)) popViewport() # Updates isnewpage # isnewpage - TRUE } -- *Sebastien Bihorel, PharmD, PhD* PKPD Scientist Cognigen Corp Email: sebastien.biho...@cognigencorp.com mailto:sebastien.biho...@cognigencorp.com Phone: (716) 633-3463 ext. 323 __ 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] Evaluation of an expression as function argument
Thanks Uwe and Baptiste *Sebastien Bihorel, PharmD, PhD* PKPD Scientist Cognigen Corp Email: sebastien.biho...@cognigencorp.com mailto:sebastien.biho...@cognigencorp.com Phone: (716) 633-3463 ext. 323 Uwe Ligges wrote: Sebastien Bihorel wrote: Dear R-users, I would like to know if is it possible to set a function argument as an evaluated expression. I have tried several syntaxes, including the following example, but could not get it anything to run. The plot function is used here but I would like to later apply the same approach to other functions. ## items - c(expression(col=2),expression(pch=2)) for (in in seq(2)) { plot(1:10, eval(items[i])) } ## Way 1: for(i in seq(2)) do.call(plot, c(list(1:10), as.list(items[i]))) Way 2 is perhaps easier for you: items - list(col=2, pch=2) for (i in seq(2)) do.call(plot, c(list(1:10), items[i])) Ways 3...n up to others... Uwe Ligges Thanks in advance for your input. Sebastien __ 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-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] Understanding padding in lattice
Thanks Paul, This function could indeed be helpful. Unfortunately, I cannot install a development version at work, so I will have to wait before using it :D Sebastien Paul Murrell wrote: Hi In the development version of R, there is a new showViewport() function that might help with debugging this sort of thing. Try ... showViewport() ... or possibly ... showViewport(newpage=TRUE) ... just after drawing your plot. Paul Deepayan Sarkar wrote: On Tue, Apr 28, 2009 at 11:51 AM, Sebastien Bihorel sebastien.biho...@cognigencorp.com wrote: Dear R-users, I am trying to understand what the different padding arguments in trellis.par.set are exactly controlling the space around lattice plots. I have used the following code as a basis for testing but it did not really help me to visualize how the value of each argument changes the margins and the plotting area. I guess a better way to visualize the effects of these padding items would be to create colored polygons for each related area of interest... but I would need to know what are these areas beforehand! You can retrieve the undelying grid layout and show it using library(grid) grid.show.layout(lattice:::lattice.getStatus(layout.details)$page.layout) which is close to what you are describing. Otherwise, there's no easy way to insert polygons in these areas that I know of. You could try setting negative padding values to see what they do. -Deepayan Any advise on how to improve this code would be greatly appreciated. Sebastien ### library(lattice) foo - data.frame(x=rep(seq(10),9),y=rep(seq(10),9),z=rep(0,90),id=rep(seq(9),each=10)) plot1 - xyplot(y+z~x|id, data=foo, type=c(p,l), distribute.type = TRUE, main=This is a test, sub=Subtitle, auto.key=T) trellis.device(pdf, file = trellis_par_test.pdf, paper=letter, #family=Courier, theme = list(fontsize = list(text = 10, points = 10))) trellis.par.set(layout.widths =list(left.padding=0, right.padding=0), layout.heights=list(top.padding =1, main.key.padding =1, axis.xlab.padding=1, key.sub.padding =1, bottom.padding =1), axis.components=list(top=list(tck=1, pad1=1, pad2=1),right=list(tck=1, pad1=1, pad2=1))) print(plot1) dev.off() ### -- *Sebastien Bihorel, PharmD, PhD* PKPD Scientist Cognigen Corp Email: sebastien.biho...@cognigencorp.com mailto:sebastien.biho...@cognigencorp.com Phone: (716) 633-3463 ext. 323 __ 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-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-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.