MilesMcBain / packup

Collect, stow, and alphabetise library() calls in your R files.
Other
59 stars 4 forks source link

enable pkg order pref #2

Open hrbrmstr opened 7 years ago

hrbrmstr commented 7 years ago

Given the increasing number of pkg namespace conflicts, suggesting an addition of checking an environment variable PACKUP_LAST (I originally thought FRAGILE_THIS_END_UP but that's silly) that can be set in .Renviron which will re-sort the library() list based on it. i.e. if the Rmd has lines like:

library(tidyverse)

… some wicked cool data tidying …

library(MASS)
library(scales)
library(raster)

… some wicked cool #rstats geospatial stats code …

the result of this script (I think) is to put:

library(tidyverse)
library(MASS)
library(scales)
library(raster)

at the top.

Unfortunately, raster::select() crushed dplyr::select() this way and it's more likely that dplyr verbs are what folks want primary (one of the functions will need to be targeted with :: and it's usually not dplyr ones).

PACKUP_LAST could be set to something like:

PACKUP_LAST=tidyverse

or

PACKUP_LAST=scales;jsonlite;tidyverse

the former would make:

library(MASS)
library(scales)
library(raster)
library(tidyverse)

at the top, and the latter would make:

library(MASS)
library(raster)
library(scales)
library(tidyverse)

at the top.

Possible bonus points for analyzing conflicts for all library()'d packages and inserting a comment or putting something in the Viewer pane with the possible conflicts.

MilesMcBain commented 7 years ago

This is great food for thought. Thanks Bob (and @maelle). I try to make my addins so that they just work without too much thought and hopefully delight users with the amount of over-engineering that goes into such a simple thing. So in that vein, always putting tidyverse packages last in the list would be the direction I think I'll go.