IRanges: interaction with model fitting
1
0
Entering edit mode
@kasper-daniel-hansen-2979
Last seen 10 months ago
United States
locfit is a package from CRAN for doing local regression (think loess). It does not have a NAMESPACE, and it uses what to my casual eyes look like a pretty standard model setup. But there is a strange thing happening when IRanges is loaded. An example is best: First get some data and define two functions that essentially does the same: library(locfit) utils::data(anorexia, package = "MASS") myData <- anorexia tmp <- function(dat) { anorex.1 <- glm(Postwt ~ lp(Prewt), family = "gaussian", data = dat) } tmp1 <- function(dat1) { tmp2 <- function(dat2) { anorex.1 <- locfit(Postwt ~ lp(Prewt), family = gaussian, data = dat2) } tmp2(dat2 = dat1) } tmp(myData) tmp1(myData) This works great. Now load IRanges and do the same library(IRanges) > tmp(myData) Error in terms.formula(formula, data = data) : 'data' argument is of the wrong type Enter a frame number, or 0 to exit 1: tmp(myData) 2: locfit(Postwt ~ lp(Prewt), family = "gaussian", data = dat) 3: eval(m, sys.frame(sys.parent())) 4: eval(m, sys.frame(sys.parent())) 5: eval(expr, envir, enclos) 6: model.frame(formula = Postwt ~ lp(Prewt), data = dat) 7: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat) 8: terms(formula, data = data) 9: terms.formula(formula, data = data) Selection: 0 > tmp1(myData) Error in inherits(x, "data.frame") : object 'dat2' not found Enter a frame number, or 0 to exit 1: tmp1(myData) 2: tmp2(dat2 = dat1) 3: locfit(Postwt ~ lp(Prewt), family = gaussian, data = dat2) 4: eval(m, sys.frame(sys.parent())) 5: eval(m, sys.frame(sys.parent())) 6: eval(expr, envir, enclos) 7: model.frame(formula = Postwt ~ lp(Prewt), data = dat2) 8: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat2) 9: is.data.frame(data) 10: inherits(x, "data.frame") Selection: 0 Clearly something seems wrong. The error messages for tmp and tmp1 are different. Perhaps the lacking NAMESPACE for locfit makes a difference. And locfit sets up the design matrix using a slightly different set of commands, that to my eye mostly look like an older paradigm. Any idea on what happens and why this is affected by IRanges? Kasper
Regression IRanges Regression IRanges • 1.3k views
ADD COMMENT
0
Entering edit mode
@martin-morgan-1513
Last seen 5 days ago
United States
On 08/20/2010 02:38 PM, Kasper Daniel Hansen wrote: > locfit is a package from CRAN for doing local regression (think > loess). It does not have a NAMESPACE, and it uses what to my casual > eyes look like a pretty standard model setup. But there is a strange > thing happening when IRanges is loaded. An example is best: > > First get some data and define two functions that essentially does the same: > > library(locfit) > utils::data(anorexia, package = "MASS") > myData <- anorexia > tmp <- function(dat) { > anorex.1 <- glm(Postwt ~ lp(Prewt), > family = "gaussian", data = dat) > } > tmp1 <- function(dat1) { > tmp2 <- function(dat2) { > anorex.1 <- locfit(Postwt ~ lp(Prewt), > family = gaussian, data = dat2) > > } > tmp2(dat2 = dat1) > } > > tmp(myData) > tmp1(myData) > > This works great. Now load IRanges and do the same > > library(IRanges) >> tmp(myData) > Error in terms.formula(formula, data = data) : > 'data' argument is of the wrong type > > Enter a frame number, or 0 to exit > > 1: tmp(myData) > 2: locfit(Postwt ~ lp(Prewt), family = "gaussian", data = dat) > 3: eval(m, sys.frame(sys.parent())) > 4: eval(m, sys.frame(sys.parent())) > 5: eval(expr, envir, enclos) > 6: model.frame(formula = Postwt ~ lp(Prewt), data = dat) > 7: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat) > 8: terms(formula, data = data) > 9: terms.formula(formula, data = data) > > Selection: 0 >> tmp1(myData) > Error in inherits(x, "data.frame") : object 'dat2' not found > > Enter a frame number, or 0 to exit > > 1: tmp1(myData) > 2: tmp2(dat2 = dat1) > 3: locfit(Postwt ~ lp(Prewt), family = gaussian, data = dat2) > 4: eval(m, sys.frame(sys.parent())) > 5: eval(m, sys.frame(sys.parent())) > 6: eval(expr, envir, enclos) > 7: model.frame(formula = Postwt ~ lp(Prewt), data = dat2) > 8: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat2) > 9: is.data.frame(data) > 10: inherits(x, "data.frame") > > Selection: 0 > > Clearly something seems wrong. The error messages for tmp and tmp1 > are different. Perhaps the lacking NAMESPACE for locfit makes a > difference. And locfit sets up the design matrix using a slightly > different set of commands, that to my eye mostly look like an older > paradigm. > > Any idea on what happens and why this is affected by IRanges? It traces to IRanges' promotion of eval to a generic. A workaround is library(IRanges) eval = base::eval Creating the generic changes the value of 'envir' (the lazy evaluation of sys.frame(sys.parent())) in the call, as shown with > trace(eval, signature=c("ANY", "ANY"), tracer=quote(print(ls(envir)))) > tmp1(anorexia) ## 'locfit' envir Tracing eval(m, sys.frame(sys.parent())) on entry [1] "base" "cens" "data" "formula" "geth" "i" "lfproc" [8] "m" "subset" "Terms" "weights" "z" Error in inherits(x, "data.frame") : object 'dat2' not found verus > eval = base::eval > trace(eval, tracer=quote(print(ls(envir)))) [1] "eval" > tmp1(anorexia) ## 'tmp2' envir Tracing eval(m, sys.frame(sys.parent())) on entry [1] "dat2" I don't think there is a robust way around this, but maybe others have a good idea? Martin > > Kasper > > _______________________________________________ > Bioconductor mailing list > Bioconductor at stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793
ADD COMMENT
0
Entering edit mode
Martin Thanks a lot for the diagnose, it was really helpful. While I have not investigated this in detail, this sugests that any model fitting package without a NAMESPACE will be adversely affected by IRanges. It seems that a (fairly) standard use of eval is broken by this (again, assuming no NAMESPACE). And the error message is pretty arcane and it took me a while to suspect IRanges. And eval is (correctly I guess) not listed as one of the masked functions when you load IRanges. While I think it makes sense to have NAMESPACEs everywhere, this will probably not be realistic. How important is it to have the function be called eval? Would it make sense to use some inspiration from cbind2 and use the name eval2? That might be a more workable fix - again that depends on how important it is to use the name eval (which I have not investigated). Thanks again, Kasper On Fri, Aug 20, 2010 at 8:32 PM, Martin Morgan <mtmorgan at="" fhcrc.org=""> wrote: > On 08/20/2010 02:38 PM, Kasper Daniel Hansen wrote: >> locfit is a package from CRAN for doing local regression (think >> loess). ?It does not have a NAMESPACE, and it uses what to my casual >> eyes look like a pretty standard model setup. ?But there is a strange >> thing happening when IRanges is loaded. ?An example is best: >> >> First get some data and define two functions that essentially does the same: >> >> library(locfit) >> utils::data(anorexia, package = "MASS") >> myData <- anorexia >> tmp <- function(dat) { >> ? ? anorex.1 <- glm(Postwt ~ lp(Prewt), >> ? ? ? ? ? ? ? ? ? ? ? ? ? ?family = "gaussian", data = dat) >> } >> tmp1 <- function(dat1) { >> ? ? tmp2 <- function(dat2) { >> ? ? ? ? anorex.1 <- locfit(Postwt ~ lp(Prewt), >> ? ? ? ? ? ? ? ? ? ? ? ? ? ?family = gaussian, data = dat2) >> >> ? ? } >> ? ? tmp2(dat2 = dat1) >> } >> >> tmp(myData) >> tmp1(myData) >> >> This works great. ?Now load IRanges and do the same >> >> library(IRanges) >>> tmp(myData) >> Error in terms.formula(formula, data = data) : >> ? 'data' argument is of the wrong type >> >> Enter a frame number, or 0 to exit >> >> 1: tmp(myData) >> 2: locfit(Postwt ~ lp(Prewt), family = "gaussian", data = dat) >> 3: eval(m, sys.frame(sys.parent())) >> 4: eval(m, sys.frame(sys.parent())) >> 5: eval(expr, envir, enclos) >> 6: model.frame(formula = Postwt ~ lp(Prewt), data = dat) >> 7: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat) >> 8: terms(formula, data = data) >> 9: terms.formula(formula, data = data) >> >> Selection: 0 >>> tmp1(myData) >> Error in inherits(x, "data.frame") : object 'dat2' not found >> >> Enter a frame number, or 0 to exit >> >> ?1: tmp1(myData) >> ?2: tmp2(dat2 = dat1) >> ?3: locfit(Postwt ~ lp(Prewt), family = gaussian, data = dat2) >> ?4: eval(m, sys.frame(sys.parent())) >> ?5: eval(m, sys.frame(sys.parent())) >> ?6: eval(expr, envir, enclos) >> ?7: model.frame(formula = Postwt ~ lp(Prewt), data = dat2) >> ?8: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat2) >> ?9: is.data.frame(data) >> 10: inherits(x, "data.frame") >> >> Selection: 0 >> >> Clearly something seems wrong. ?The error messages for tmp and tmp1 >> are different. ?Perhaps the lacking NAMESPACE for locfit makes a >> difference. ?And locfit sets up the design matrix using a slightly >> different set of commands, that to my eye mostly look like an older >> paradigm. >> >> Any idea on what happens and why this is affected by IRanges? > > It traces to IRanges' promotion of eval to a generic. A workaround is > > library(IRanges) > eval = base::eval > > Creating the generic changes the value of 'envir' (the lazy evaluation > of sys.frame(sys.parent())) in the call, as shown with > >> trace(eval, signature=c("ANY", "ANY"), tracer=quote(print(ls(envir)))) >> tmp1(anorexia) ## 'locfit' envir > Tracing eval(m, sys.frame(sys.parent())) on entry > ?[1] "base" ? ?"cens" ? ?"data" ? ?"formula" "geth" ? ?"i" ? ? ? "lfproc" > ?[8] "m" ? ? ? "subset" ?"Terms" ? "weights" "z" > Error in inherits(x, "data.frame") : object 'dat2' not found > > verus > >> eval = base::eval >> trace(eval, tracer=quote(print(ls(envir)))) > [1] "eval" >> tmp1(anorexia) ## 'tmp2' envir > Tracing eval(m, sys.frame(sys.parent())) on entry > [1] "dat2" > > I don't think there is a robust way around this, but maybe others have a > good idea? > > Martin >> >> Kasper >> >> _______________________________________________ >> Bioconductor mailing list >> Bioconductor at stat.math.ethz.ch >> https://stat.ethz.ch/mailman/listinfo/bioconductor >> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor > > > -- > Martin Morgan > Computational Biology / Fred Hutchinson Cancer Research Center > 1100 Fairview Ave. N. > PO Box 19024 Seattle, WA 98109 > > Location: Arnold Building M1 B861 > Phone: (206) 667-2793 >
ADD REPLY
0
Entering edit mode
On Fri, Aug 20, 2010 at 5:32 PM, Martin Morgan <mtmorgan@fhcrc.org> wrote: > On 08/20/2010 02:38 PM, Kasper Daniel Hansen wrote: > > locfit is a package from CRAN for doing local regression (think > > loess). It does not have a NAMESPACE, and it uses what to my casual > > eyes look like a pretty standard model setup. But there is a strange > > thing happening when IRanges is loaded. An example is best: > > > > First get some data and define two functions that essentially does the > same: > > > > library(locfit) > > utils::data(anorexia, package = "MASS") > > myData <- anorexia > > tmp <- function(dat) { > > anorex.1 <- glm(Postwt ~ lp(Prewt), > > family = "gaussian", data = dat) > > } > > tmp1 <- function(dat1) { > > tmp2 <- function(dat2) { > > anorex.1 <- locfit(Postwt ~ lp(Prewt), > > family = gaussian, data = dat2) > > > > } > > tmp2(dat2 = dat1) > > } > > > > tmp(myData) > > tmp1(myData) > > > > This works great. Now load IRanges and do the same > > > > library(IRanges) > >> tmp(myData) > > Error in terms.formula(formula, data = data) : > > 'data' argument is of the wrong type > > > > Enter a frame number, or 0 to exit > > > > 1: tmp(myData) > > 2: locfit(Postwt ~ lp(Prewt), family = "gaussian", data = dat) > > 3: eval(m, sys.frame(sys.parent())) > > 4: eval(m, sys.frame(sys.parent())) > > 5: eval(expr, envir, enclos) > > 6: model.frame(formula = Postwt ~ lp(Prewt), data = dat) > > 7: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat) > > 8: terms(formula, data = data) > > 9: terms.formula(formula, data = data) > > > > Selection: 0 > >> tmp1(myData) > > Error in inherits(x, "data.frame") : object 'dat2' not found > > > > Enter a frame number, or 0 to exit > > > > 1: tmp1(myData) > > 2: tmp2(dat2 = dat1) > > 3: locfit(Postwt ~ lp(Prewt), family = gaussian, data = dat2) > > 4: eval(m, sys.frame(sys.parent())) > > 5: eval(m, sys.frame(sys.parent())) > > 6: eval(expr, envir, enclos) > > 7: model.frame(formula = Postwt ~ lp(Prewt), data = dat2) > > 8: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat2) > > 9: is.data.frame(data) > > 10: inherits(x, "data.frame") > > > > Selection: 0 > > > > Clearly something seems wrong. The error messages for tmp and tmp1 > > are different. Perhaps the lacking NAMESPACE for locfit makes a > > difference. And locfit sets up the design matrix using a slightly > > different set of commands, that to my eye mostly look like an older > > paradigm. > > > > Any idea on what happens and why this is affected by IRanges? > > It traces to IRanges' promotion of eval to a generic. A workaround is > > library(IRanges) > eval = base::eval > > Creating the generic changes the value of 'envir' (the lazy evaluation > of sys.frame(sys.parent())) in the call, as shown with > > > trace(eval, signature=c("ANY", "ANY"), tracer=quote(print(ls(envir)))) > > tmp1(anorexia) ## 'locfit' envir > Tracing eval(m, sys.frame(sys.parent())) on entry > [1] "base" "cens" "data" "formula" "geth" "i" "lfproc" > [8] "m" "subset" "Terms" "weights" "z" > Error in inherits(x, "data.frame") : object 'dat2' not found > > verus > > > eval = base::eval > > trace(eval, tracer=quote(print(ls(envir)))) > [1] "eval" > > tmp1(anorexia) ## 'tmp2' envir > Tracing eval(m, sys.frame(sys.parent())) on entry > [1] "dat2" > > I don't think there is a robust way around this, but maybe others have a > good idea? > > I just added a non-standard generic for "eval" that forces the evaluation of the arguments. Works in this case. Is that sensible? Michael > Martin > > > > Kasper > > > > _______________________________________________ > > Bioconductor mailing list > > Bioconductor@stat.math.ethz.ch > > https://stat.ethz.ch/mailman/listinfo/bioconductor > > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > > > -- > Martin Morgan > Computational Biology / Fred Hutchinson Cancer Research Center > 1100 Fairview Ave. N. > PO Box 19024 Seattle, WA 98109 > > Location: Arnold Building M1 B861 > Phone: (206) 667-2793 > [[alternative HTML version deleted]]
ADD REPLY
0
Entering edit mode
Btw, I also find it interesting that if sys.frame(sys.parent()) is replaced with parent.frame(), everything works just fine. Looking at the internals, it seems parent.frame() uses a direct pointer to the parent, which seems to be robust to the lazy evaluation, whereas sys.parent() finds the position of that pointer in the stack, which seems independent of lazy evaluation. Michael On Sun, Aug 22, 2010 at 1:25 AM, Michael Lawrence <michafla@gene.com> wrote: > > > On Fri, Aug 20, 2010 at 5:32 PM, Martin Morgan <mtmorgan@fhcrc.org> wrote: > >> On 08/20/2010 02:38 PM, Kasper Daniel Hansen wrote: >> > locfit is a package from CRAN for doing local regression (think >> > loess). It does not have a NAMESPACE, and it uses what to my casual >> > eyes look like a pretty standard model setup. But there is a strange >> > thing happening when IRanges is loaded. An example is best: >> > >> > First get some data and define two functions that essentially does the >> same: >> > >> > library(locfit) >> > utils::data(anorexia, package = "MASS") >> > myData <- anorexia >> > tmp <- function(dat) { >> > anorex.1 <- glm(Postwt ~ lp(Prewt), >> > family = "gaussian", data = dat) >> > } >> > tmp1 <- function(dat1) { >> > tmp2 <- function(dat2) { >> > anorex.1 <- locfit(Postwt ~ lp(Prewt), >> > family = gaussian, data = dat2) >> > >> > } >> > tmp2(dat2 = dat1) >> > } >> > >> > tmp(myData) >> > tmp1(myData) >> > >> > This works great. Now load IRanges and do the same >> > >> > library(IRanges) >> >> tmp(myData) >> > Error in terms.formula(formula, data = data) : >> > 'data' argument is of the wrong type >> > >> > Enter a frame number, or 0 to exit >> > >> > 1: tmp(myData) >> > 2: locfit(Postwt ~ lp(Prewt), family = "gaussian", data = dat) >> > 3: eval(m, sys.frame(sys.parent())) >> > 4: eval(m, sys.frame(sys.parent())) >> > 5: eval(expr, envir, enclos) >> > 6: model.frame(formula = Postwt ~ lp(Prewt), data = dat) >> > 7: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat) >> > 8: terms(formula, data = data) >> > 9: terms.formula(formula, data = data) >> > >> > Selection: 0 >> >> tmp1(myData) >> > Error in inherits(x, "data.frame") : object 'dat2' not found >> > >> > Enter a frame number, or 0 to exit >> > >> > 1: tmp1(myData) >> > 2: tmp2(dat2 = dat1) >> > 3: locfit(Postwt ~ lp(Prewt), family = gaussian, data = dat2) >> > 4: eval(m, sys.frame(sys.parent())) >> > 5: eval(m, sys.frame(sys.parent())) >> > 6: eval(expr, envir, enclos) >> > 7: model.frame(formula = Postwt ~ lp(Prewt), data = dat2) >> > 8: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat2) >> > 9: is.data.frame(data) >> > 10: inherits(x, "data.frame") >> > >> > Selection: 0 >> > >> > Clearly something seems wrong. The error messages for tmp and tmp1 >> > are different. Perhaps the lacking NAMESPACE for locfit makes a >> > difference. And locfit sets up the design matrix using a slightly >> > different set of commands, that to my eye mostly look like an older >> > paradigm. >> > >> > Any idea on what happens and why this is affected by IRanges? >> >> It traces to IRanges' promotion of eval to a generic. A workaround is >> >> library(IRanges) >> eval = base::eval >> >> Creating the generic changes the value of 'envir' (the lazy evaluation >> of sys.frame(sys.parent())) in the call, as shown with >> >> > trace(eval, signature=c("ANY", "ANY"), tracer=quote(print(ls(envir)))) >> > tmp1(anorexia) ## 'locfit' envir >> Tracing eval(m, sys.frame(sys.parent())) on entry >> [1] "base" "cens" "data" "formula" "geth" "i" "lfproc" >> [8] "m" "subset" "Terms" "weights" "z" >> Error in inherits(x, "data.frame") : object 'dat2' not found >> >> verus >> >> > eval = base::eval >> > trace(eval, tracer=quote(print(ls(envir)))) >> [1] "eval" >> > tmp1(anorexia) ## 'tmp2' envir >> Tracing eval(m, sys.frame(sys.parent())) on entry >> [1] "dat2" >> >> I don't think there is a robust way around this, but maybe others have a >> good idea? >> >> > I just added a non-standard generic for "eval" that forces the evaluation > of the arguments. Works in this case. Is that sensible? > > Michael > > > >> Martin >> > >> > Kasper >> > >> > _______________________________________________ >> > Bioconductor mailing list >> > Bioconductor@stat.math.ethz.ch >> > https://stat.ethz.ch/mailman/listinfo/bioconductor >> > Search the archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor >> >> >> -- >> Martin Morgan >> Computational Biology / Fred Hutchinson Cancer Research Center >> 1100 Fairview Ave. N. >> PO Box 19024 Seattle, WA 98109 >> >> Location: Arnold Building M1 B861 >> Phone: (206) 667-2793 >> > > [[alternative HTML version deleted]]
ADD REPLY
0
Entering edit mode
On 08/22/2010 01:25 AM, Michael Lawrence wrote: > On Fri, Aug 20, 2010 at 5:32 PM, Martin Morgan <mtmorgan at="" fhcrc.org=""> wrote: > >> On 08/20/2010 02:38 PM, Kasper Daniel Hansen wrote: >>> locfit is a package from CRAN for doing local regression (think >>> loess). It does not have a NAMESPACE, and it uses what to my casual >>> eyes look like a pretty standard model setup. But there is a strange >>> thing happening when IRanges is loaded. An example is best: >>> >>> First get some data and define two functions that essentially does the >> same: >>> >>> library(locfit) >>> utils::data(anorexia, package = "MASS") >>> myData <- anorexia >>> tmp <- function(dat) { >>> anorex.1 <- glm(Postwt ~ lp(Prewt), >>> family = "gaussian", data = dat) >>> } >>> tmp1 <- function(dat1) { >>> tmp2 <- function(dat2) { >>> anorex.1 <- locfit(Postwt ~ lp(Prewt), >>> family = gaussian, data = dat2) >>> >>> } >>> tmp2(dat2 = dat1) >>> } >>> >>> tmp(myData) >>> tmp1(myData) >>> >>> This works great. Now load IRanges and do the same >>> >>> library(IRanges) >>>> tmp(myData) >>> Error in terms.formula(formula, data = data) : >>> 'data' argument is of the wrong type >>> >>> Enter a frame number, or 0 to exit >>> >>> 1: tmp(myData) >>> 2: locfit(Postwt ~ lp(Prewt), family = "gaussian", data = dat) >>> 3: eval(m, sys.frame(sys.parent())) >>> 4: eval(m, sys.frame(sys.parent())) >>> 5: eval(expr, envir, enclos) >>> 6: model.frame(formula = Postwt ~ lp(Prewt), data = dat) >>> 7: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat) >>> 8: terms(formula, data = data) >>> 9: terms.formula(formula, data = data) >>> >>> Selection: 0 >>>> tmp1(myData) >>> Error in inherits(x, "data.frame") : object 'dat2' not found >>> >>> Enter a frame number, or 0 to exit >>> >>> 1: tmp1(myData) >>> 2: tmp2(dat2 = dat1) >>> 3: locfit(Postwt ~ lp(Prewt), family = gaussian, data = dat2) >>> 4: eval(m, sys.frame(sys.parent())) >>> 5: eval(m, sys.frame(sys.parent())) >>> 6: eval(expr, envir, enclos) >>> 7: model.frame(formula = Postwt ~ lp(Prewt), data = dat2) >>> 8: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat2) >>> 9: is.data.frame(data) >>> 10: inherits(x, "data.frame") >>> >>> Selection: 0 >>> >>> Clearly something seems wrong. The error messages for tmp and tmp1 >>> are different. Perhaps the lacking NAMESPACE for locfit makes a >>> difference. And locfit sets up the design matrix using a slightly >>> different set of commands, that to my eye mostly look like an older >>> paradigm. >>> >>> Any idea on what happens and why this is affected by IRanges? >> >> It traces to IRanges' promotion of eval to a generic. A workaround is >> >> library(IRanges) >> eval = base::eval >> >> Creating the generic changes the value of 'envir' (the lazy evaluation >> of sys.frame(sys.parent())) in the call, as shown with >> >>> trace(eval, signature=c("ANY", "ANY"), tracer=quote(print(ls(envir)))) >>> tmp1(anorexia) ## 'locfit' envir >> Tracing eval(m, sys.frame(sys.parent())) on entry >> [1] "base" "cens" "data" "formula" "geth" "i" "lfproc" >> [8] "m" "subset" "Terms" "weights" "z" >> Error in inherits(x, "data.frame") : object 'dat2' not found >> >> verus >> >>> eval = base::eval >>> trace(eval, tracer=quote(print(ls(envir)))) >> [1] "eval" >>> tmp1(anorexia) ## 'tmp2' envir >> Tracing eval(m, sys.frame(sys.parent())) on entry >> [1] "dat2" >> >> I don't think there is a robust way around this, but maybe others have a >> good idea? >> >> > I just added a non-standard generic for "eval" that forces the evaluation of > the arguments. Works in this case. Is that sensible? I can't think of an example where this will be positively wrong; it won't surprise me when one is reported. I'm ok with the nonstandardGeneric until then. Martin > > Michael > > > >> Martin >>> >>> Kasper >>> >>> _______________________________________________ >>> Bioconductor mailing list >>> Bioconductor at stat.math.ethz.ch >>> https://stat.ethz.ch/mailman/listinfo/bioconductor >>> Search the archives: >> http://news.gmane.org/gmane.science.biology.informatics.conductor >> >> >> -- >> Martin Morgan >> Computational Biology / Fred Hutchinson Cancer Research Center >> 1100 Fairview Ave. N. >> PO Box 19024 Seattle, WA 98109 >> >> Location: Arnold Building M1 B861 >> Phone: (206) 667-2793 >> > -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793
ADD REPLY
0
Entering edit mode
It's not a fix-all, e.g. callNextMethod with arguments (admittedly unusual) would still behave unexpectedly. But, I agree, it's hard to think of cases where forcing either 'envir' or 'enclos' to "eval" would be undesirable. It's not like anyone wants to deparse(substitute()) them. Michael On Sun, Aug 22, 2010 at 12:49 PM, Martin Morgan <mtmorgan@fhcrc.org> wrote: > On 08/22/2010 01:25 AM, Michael Lawrence wrote: > > On Fri, Aug 20, 2010 at 5:32 PM, Martin Morgan <mtmorgan@fhcrc.org> > wrote: > > > >> On 08/20/2010 02:38 PM, Kasper Daniel Hansen wrote: > >>> locfit is a package from CRAN for doing local regression (think > >>> loess). It does not have a NAMESPACE, and it uses what to my casual > >>> eyes look like a pretty standard model setup. But there is a strange > >>> thing happening when IRanges is loaded. An example is best: > >>> > >>> First get some data and define two functions that essentially does the > >> same: > >>> > >>> library(locfit) > >>> utils::data(anorexia, package = "MASS") > >>> myData <- anorexia > >>> tmp <- function(dat) { > >>> anorex.1 <- glm(Postwt ~ lp(Prewt), > >>> family = "gaussian", data = dat) > >>> } > >>> tmp1 <- function(dat1) { > >>> tmp2 <- function(dat2) { > >>> anorex.1 <- locfit(Postwt ~ lp(Prewt), > >>> family = gaussian, data = dat2) > >>> > >>> } > >>> tmp2(dat2 = dat1) > >>> } > >>> > >>> tmp(myData) > >>> tmp1(myData) > >>> > >>> This works great. Now load IRanges and do the same > >>> > >>> library(IRanges) > >>>> tmp(myData) > >>> Error in terms.formula(formula, data = data) : > >>> 'data' argument is of the wrong type > >>> > >>> Enter a frame number, or 0 to exit > >>> > >>> 1: tmp(myData) > >>> 2: locfit(Postwt ~ lp(Prewt), family = "gaussian", data = dat) > >>> 3: eval(m, sys.frame(sys.parent())) > >>> 4: eval(m, sys.frame(sys.parent())) > >>> 5: eval(expr, envir, enclos) > >>> 6: model.frame(formula = Postwt ~ lp(Prewt), data = dat) > >>> 7: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat) > >>> 8: terms(formula, data = data) > >>> 9: terms.formula(formula, data = data) > >>> > >>> Selection: 0 > >>>> tmp1(myData) > >>> Error in inherits(x, "data.frame") : object 'dat2' not found > >>> > >>> Enter a frame number, or 0 to exit > >>> > >>> 1: tmp1(myData) > >>> 2: tmp2(dat2 = dat1) > >>> 3: locfit(Postwt ~ lp(Prewt), family = gaussian, data = dat2) > >>> 4: eval(m, sys.frame(sys.parent())) > >>> 5: eval(m, sys.frame(sys.parent())) > >>> 6: eval(expr, envir, enclos) > >>> 7: model.frame(formula = Postwt ~ lp(Prewt), data = dat2) > >>> 8: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat2) > >>> 9: is.data.frame(data) > >>> 10: inherits(x, "data.frame") > >>> > >>> Selection: 0 > >>> > >>> Clearly something seems wrong. The error messages for tmp and tmp1 > >>> are different. Perhaps the lacking NAMESPACE for locfit makes a > >>> difference. And locfit sets up the design matrix using a slightly > >>> different set of commands, that to my eye mostly look like an older > >>> paradigm. > >>> > >>> Any idea on what happens and why this is affected by IRanges? > >> > >> It traces to IRanges' promotion of eval to a generic. A workaround is > >> > >> library(IRanges) > >> eval = base::eval > >> > >> Creating the generic changes the value of 'envir' (the lazy evaluation > >> of sys.frame(sys.parent())) in the call, as shown with > >> > >>> trace(eval, signature=c("ANY", "ANY"), tracer=quote(print(ls(envir)))) > >>> tmp1(anorexia) ## 'locfit' envir > >> Tracing eval(m, sys.frame(sys.parent())) on entry > >> [1] "base" "cens" "data" "formula" "geth" "i" > "lfproc" > >> [8] "m" "subset" "Terms" "weights" "z" > >> Error in inherits(x, "data.frame") : object 'dat2' not found > >> > >> verus > >> > >>> eval = base::eval > >>> trace(eval, tracer=quote(print(ls(envir)))) > >> [1] "eval" > >>> tmp1(anorexia) ## 'tmp2' envir > >> Tracing eval(m, sys.frame(sys.parent())) on entry > >> [1] "dat2" > >> > >> I don't think there is a robust way around this, but maybe others have a > >> good idea? > >> > >> > > I just added a non-standard generic for "eval" that forces the evaluation > of > > the arguments. Works in this case. Is that sensible? > > I can't think of an example where this will be positively wrong; it > won't surprise me when one is reported. I'm ok with the > nonstandardGeneric until then. Martin > > > > > Michael > > > > > > > >> Martin > >>> > >>> Kasper > >>> > >>> _______________________________________________ > >>> Bioconductor mailing list > >>> Bioconductor@stat.math.ethz.ch > >>> https://stat.ethz.ch/mailman/listinfo/bioconductor > >>> Search the archives: > >> http://news.gmane.org/gmane.science.biology.informatics.conductor > >> > >> > >> -- > >> Martin Morgan > >> Computational Biology / Fred Hutchinson Cancer Research Center > >> 1100 Fairview Ave. N. > >> PO Box 19024 Seattle, WA 98109 > >> > >> Location: Arnold Building M1 B861 > >> Phone: (206) 667-2793 > >> > > > > > -- > Martin Morgan > Computational Biology / Fred Hutchinson Cancer Research Center > 1100 Fairview Ave. N. > PO Box 19024 Seattle, WA 98109 > > Location: Arnold Building M1 B861 > Phone: (206) 667-2793 > [[alternative HTML version deleted]]
ADD REPLY
0
Entering edit mode
Thanks a lot for the help. I agree with the fix and I am also surprised that parent.frame() is different from sys.frame(sys.parent()). I'll contact the locfit maintainer and see if I can get a NAMESPACE and use parent.frame and possibly a few other things. But that only addresses one out of many packages on CRAN. Kasper On Sun, Aug 22, 2010 at 5:10 PM, Michael Lawrence <lawrence.michael at="" gene.com=""> wrote: > It's not a fix-all, e.g. callNextMethod with arguments (admittedly unusual) > would still behave unexpectedly.? But, I agree, it's hard to think of cases > where forcing either 'envir' or 'enclos' to "eval" would be undesirable. > It's not like anyone wants to deparse(substitute()) them. > > Michael > > On Sun, Aug 22, 2010 at 12:49 PM, Martin Morgan <mtmorgan at="" fhcrc.org=""> wrote: >> >> On 08/22/2010 01:25 AM, Michael Lawrence wrote: >> > On Fri, Aug 20, 2010 at 5:32 PM, Martin Morgan <mtmorgan at="" fhcrc.org=""> >> > wrote: >> > >> >> On 08/20/2010 02:38 PM, Kasper Daniel Hansen wrote: >> >>> locfit is a package from CRAN for doing local regression (think >> >>> loess). ?It does not have a NAMESPACE, and it uses what to my casual >> >>> eyes look like a pretty standard model setup. ?But there is a strange >> >>> thing happening when IRanges is loaded. ?An example is best: >> >>> >> >>> First get some data and define two functions that essentially does the >> >> same: >> >>> >> >>> library(locfit) >> >>> utils::data(anorexia, package = "MASS") >> >>> myData <- anorexia >> >>> tmp <- function(dat) { >> >>> ? ? anorex.1 <- glm(Postwt ~ lp(Prewt), >> >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ?family = "gaussian", data = dat) >> >>> } >> >>> tmp1 <- function(dat1) { >> >>> ? ? tmp2 <- function(dat2) { >> >>> ? ? ? ? anorex.1 <- locfit(Postwt ~ lp(Prewt), >> >>> ? ? ? ? ? ? ? ? ? ? ? ? ? ?family = gaussian, data = dat2) >> >>> >> >>> ? ? } >> >>> ? ? tmp2(dat2 = dat1) >> >>> } >> >>> >> >>> tmp(myData) >> >>> tmp1(myData) >> >>> >> >>> This works great. ?Now load IRanges and do the same >> >>> >> >>> library(IRanges) >> >>>> tmp(myData) >> >>> Error in terms.formula(formula, data = data) : >> >>> ? 'data' argument is of the wrong type >> >>> >> >>> Enter a frame number, or 0 to exit >> >>> >> >>> 1: tmp(myData) >> >>> 2: locfit(Postwt ~ lp(Prewt), family = "gaussian", data = dat) >> >>> 3: eval(m, sys.frame(sys.parent())) >> >>> 4: eval(m, sys.frame(sys.parent())) >> >>> 5: eval(expr, envir, enclos) >> >>> 6: model.frame(formula = Postwt ~ lp(Prewt), data = dat) >> >>> 7: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat) >> >>> 8: terms(formula, data = data) >> >>> 9: terms.formula(formula, data = data) >> >>> >> >>> Selection: 0 >> >>>> tmp1(myData) >> >>> Error in inherits(x, "data.frame") : object 'dat2' not found >> >>> >> >>> Enter a frame number, or 0 to exit >> >>> >> >>> ?1: tmp1(myData) >> >>> ?2: tmp2(dat2 = dat1) >> >>> ?3: locfit(Postwt ~ lp(Prewt), family = gaussian, data = dat2) >> >>> ?4: eval(m, sys.frame(sys.parent())) >> >>> ?5: eval(m, sys.frame(sys.parent())) >> >>> ?6: eval(expr, envir, enclos) >> >>> ?7: model.frame(formula = Postwt ~ lp(Prewt), data = dat2) >> >>> ?8: model.frame.default(formula = Postwt ~ lp(Prewt), data = dat2) >> >>> ?9: is.data.frame(data) >> >>> 10: inherits(x, "data.frame") >> >>> >> >>> Selection: 0 >> >>> >> >>> Clearly something seems wrong. ?The error messages for tmp and tmp1 >> >>> are different. ?Perhaps the lacking NAMESPACE for locfit makes a >> >>> difference. ?And locfit sets up the design matrix using a slightly >> >>> different set of commands, that to my eye mostly look like an older >> >>> paradigm. >> >>> >> >>> Any idea on what happens and why this is affected by IRanges? >> >> >> >> It traces to IRanges' promotion of eval to a generic. A workaround is >> >> >> >> library(IRanges) >> >> eval = base::eval >> >> >> >> Creating the generic changes the value of 'envir' (the lazy evaluation >> >> of sys.frame(sys.parent())) in the call, as shown with >> >> >> >>> trace(eval, signature=c("ANY", "ANY"), tracer=quote(print(ls(envir)))) >> >>> tmp1(anorexia) ## 'locfit' envir >> >> Tracing eval(m, sys.frame(sys.parent())) on entry >> >> ?[1] "base" ? ?"cens" ? ?"data" ? ?"formula" "geth" ? ?"i" >> >> "lfproc" >> >> ?[8] "m" ? ? ? "subset" ?"Terms" ? "weights" "z" >> >> Error in inherits(x, "data.frame") : object 'dat2' not found >> >> >> >> verus >> >> >> >>> eval = base::eval >> >>> trace(eval, tracer=quote(print(ls(envir)))) >> >> [1] "eval" >> >>> tmp1(anorexia) ## 'tmp2' envir >> >> Tracing eval(m, sys.frame(sys.parent())) on entry >> >> [1] "dat2" >> >> >> >> I don't think there is a robust way around this, but maybe others have >> >> a >> >> good idea? >> >> >> >> >> > I just added a non-standard generic for "eval" that forces the >> > evaluation of >> > the arguments. Works in this case. Is that sensible? >> >> I can't think of an example where this will be positively wrong; it >> won't surprise me when one is reported. I'm ok with the >> nonstandardGeneric until then. Martin >> >> > >> > Michael >> > >> > >> > >> >> Martin >> >>> >> >>> Kasper >> >>> >> >>> _______________________________________________ >> >>> Bioconductor mailing list >> >>> Bioconductor at stat.math.ethz.ch >> >>> https://stat.ethz.ch/mailman/listinfo/bioconductor >> >>> Search the archives: >> >> http://news.gmane.org/gmane.science.biology.informatics.conductor >> >> >> >> >> >> -- >> >> Martin Morgan >> >> Computational Biology / Fred Hutchinson Cancer Research Center >> >> 1100 Fairview Ave. N. >> >> PO Box 19024 Seattle, WA 98109 >> >> >> >> Location: Arnold Building M1 B861 >> >> Phone: (206) 667-2793 >> >> >> > >> >> >> -- >> Martin Morgan >> Computational Biology / Fred Hutchinson Cancer Research Center >> 1100 Fairview Ave. N. >> PO Box 19024 Seattle, WA 98109 >> >> Location: Arnold Building M1 B861 >> Phone: (206) 667-2793 > >
ADD REPLY

Login before adding your answer.

Traffic: 964 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6