Closed margoal1 closed 3 years ago
I found this sentence in the News for R v4.0.0, https://cran.r-project.org/doc/manuals/r-devel/NEWS.html:
S3 method lookup now by default skips the elements of the search path between the global and base environments.
Do you think this might be related? I think the predictdf.xxx functions are related to methods.... in ggplot2 the predictdf function calls UseMethod("predictdf") https://github.com/tidyverse/ggplot2/blob/master/R/stat-smooth-methods.r
Found the below advice from https://adv-r.hadley.nz/s3.html?q=UseMethod#s3-methods. The bolding is mine:
13.4.3 Creating methods There are two wrinkles to be aware of when you create a new method:
- First, you should only ever write a method if you own the generic or the class. R will allow you to define a method even if you don’t, but it is exceedingly bad manners. Instead, work with the author of either the generic or the class to add the method in their code.
Maybe we should suggest predictdf.nls be added to ggplot2?
Solution: use @exportS3Method ggplot2::predictdf as in the reference below
I'm glad you found it;
Interestingly the tidyverse doesn't follow their own advice with broom
, they instead encourage others to write methods for linear models.
Found the below advice from https://adv-r.hadley.nz/s3.html?q=UseMethod#s3-methods. The bolding is mine:
13.4.3 Creating methods There are two wrinkles to be aware of when you create a new method:
- First, you should only ever write a method if you own the generic or the class. R will allow you to define a method even if you don’t, but it is exceedingly bad manners. Instead, work with the author of either the generic or the class to add the method in their code.
Maybe we should suggest predictdf.nls be added to ggplot2?
geom_smooth with method = "nls" does not produce desired behavior. The issue has been isolated to the definition of predictdf.nls function, which works when sourced to .GlobalEnv, or when compiled in the package with R 3.6.1 and ggplot2 3.2.1, but does not work when compiled within the package with R 4.0.2 and ggplot2 3.3.2. Details below.
Function predictdf.nls was created to provide mean and confidence intervals from a nls fit to supply to geom_smooth. Because of the naming of the predictdf.nls function, geom_smooth is supposed to call it automatically (similar to how geom_smooth calls predictdf.glm & predictdf.loess depending on the method). It was working perfectly fine for ggplot2 v3.2.1 / R v3.6.1, but somewhere between there and ggplot2 v3.3.2 / R v4.0.2 it’s now broken. Below are details on when it does and does not work.
Details on when it does and does not work:
There is some communication issue between the package-defined predictdf.nls function and the ggplot2 geom_smooth function which I don’t understand.
Below is the function and example code.
In previous R & ggplot2 versions:
with most recent R and ggplot2 versions: