DoseResponse / drc

Fitting dose-response models in R
https://doseresponse.github.io/drc/
21 stars 16 forks source link

MASS import causes name conflicts (e.g. with select function from dplyr) #12

Open lapotok opened 4 years ago

lapotok commented 4 years ago

Dear drc developers,

I like your package very much and use it all the time in my work. Also I enjoy using tidyverse metapackage with its pipelines. But there's an issue that prevents me from using both with comfort. I can see that you are using MASS package for some calculations. Unfortunately, importing all its functions into user environment can cause name conflicts (e.g. select() function from dplyr). Currently I have to manually detach MASS package to keep working normally with select() from dplyr, or explicitly state dplyr::select(), or use drc functions like drc::drm(formula, data, fct = drc::LL.4() ...) to prevent attaching MASS. I'd suggest to run MASS functions without attaching them, like MASS::boxcox().

Best regards, Evgeny

nlubock commented 3 years ago

I totally agree with your suggestion @lapotok . That said, a quick workaround is to load tidyverse after drc.

Loading tidyverse before drc:

> library(tidyverse)
── Attaching packages ────────────────────────────────── tidyverse 1.3.0 ──
✓ ggplot2 3.3.3     ✓ purrr   0.3.4
✓ tibble  3.0.5     ✓ dplyr   1.0.3
✓ tidyr   1.1.2     ✓ stringr 1.4.0
✓ readr   1.3.1     ✓ forcats 0.5.0
── Conflicts ───────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()
> library(drc)
Loading required package: MASS

Attaching package: ‘MASS’

The following object is masked from ‘package:dplyr’:

    select

'drc' has been loaded.

Please cite R and 'drc' if used for a publication,
for references type 'citation()' and 'citation('drc')'.

Attaching package: ‘drc’

The following objects are masked from ‘package:stats’:

    gaussian, getInitial

> mtcars %>% 
+     select(mpg)
Error in select(., mpg) : unused argument (mpg)

Loading tidyverse after drc:

> library(drc)
Loading required package: MASS

'drc' has been loaded.

Please cite R and 'drc' if used for a publication,
for references type 'citation()' and 'citation('drc')'.

Attaching package: ‘drc’

The following objects are masked from ‘package:stats’:

    gaussian, getInitial

> library(tidyverse)
── Attaching packages ─────────────────────────────────── tidyverse 1.3.0 ──
✓ ggplot2 3.3.3     ✓ purrr   0.3.4
✓ tibble  3.0.5     ✓ dplyr   1.0.3
✓ tidyr   1.1.2     ✓ stringr 1.4.0
✓ readr   1.3.1     ✓ forcats 0.5.0
── Conflicts ────────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()
x dplyr::select() masks MASS::select()

> mtcars %>% 
+     select(mpg)
                     mpg
Mazda RX4           21.0
Mazda RX4 Wag       21.0
Datsun 710          22.8
Hornet 4 Drive      21.4
Hornet Sportabout   18.7
...

You can see from the conflicts section the the only function tidyverse masks from MASS is select