Data Science Desktop Survival Guide
by Graham Williams |
|||||
Functions from Packages |
20200105
Generally in commentary we will use this notation to clearly identify the package which provides the function. In our interactive R usage and in scripts we tend not to use the namespace notation. It can clutter the code and arguably reduce its readability even though there is the benefit of clearly identifying where the function comes from.
For common packages we tend not to use namespaces but for less well-known packages a namespace at least on first usage provides valuable information. Also, when a package provides a function that has the same name as a function in another namespace, it is useful to explicitly supply the namespace prefix.
Preferred
library(dplyr) # Data wranlging, mutate().
library(lubridate) # Dates and time, ymd_hm(). library(ggplot2) # Visualize data. ds <- get(dsname) %>% mutate(timestamp=ymd_hm(paste(date, time))) %>% ggplot(aes(timestamp, measure)) + geom_line() + geom_smooth()
Alternative
|
ds <- get(dsname) %>%
dplyr::mutate(timestamp= lubridate::ymd_hm(paste(date, time))) %>% ggplot2::ggplot(ggplot2::aes(timestamp, measure)) + ggplot2::geom_line() + ggplot2::geom_smooth()
|