are there packages that cannot be installed together?

I've been trying to clean data and get an error saying that the pipe function connect be found, so I library(dplyr). I tried this code but then get another error about the separate function.

hourly_activity <- hourly_calories %>%
left_join(hourly_intensities, by = c("Id", "ActivityHour")) %>%
left_join(hourly_steps, by = c("Id", "ActivityHour")) %>%
clean_names() %>%
mutate(activity_hour = mdy_hms(activity_hour),
day_week = weekdays(activity_hour)) %>%
separate(col = activity_hour, into = c("date", "time"), sep = " ") %>%
mutate(date = ymd(date)) %>%
select(-"average_intensity")

Above is the code in trying to run. I have a feeling it has to do with my installed packages. A list of my installed packages are below. Are any of these packages unable to used in the same project?

install.packages("tidyverse")
install.packages("lubridate")
install.packages("dplyr")
install.packages("ggplot2")
install.packages("tidyr")
install.packages("here")
install.packages("skimr")
install.packages("janitor")
install.packages("readr")
install.packages("openair")
install.packages("psych")
install.packages("DataExplorer")
install.packages("VennDiagram")
install.packages("formattable")
install.packages("reshape2")
install.packages("scales")
install.packages("ggpubr")
install.packages("ggrepel")
install.packages("rmarkdown")

You can always use a package but you may need to explicitly say which package to use for a certain function. You can think about the loading of packages as the creation of a stack of sources for function names. The names source (Package) most recently loaded gets precedence. You can see the order of packages with the search() function. Immediately after starting R, I get this list of packages returned by search().

> search()
 [1] ".GlobalEnv"        "tools:rstudio"     "package:stats"    
 [4] "package:graphics"  "package:grDevices" "package:utils"    
 [7] "package:datasets"  "package:methods"   "Autoloads"        
[10] "package:base"     

The .GlobalEnv, that is, objects you made with code, is first, followed by tools:rstudio. When I load tidyr, it moves into the second position.

> library(tidyr)
> search()
 [1] ".GlobalEnv"        "package:tidyr"     "tools:rstudio"    
 [4] "package:stats"     "package:graphics"  "package:grDevices"
 [7] "package:utils"     "package:datasets"  "package:methods"  
[10] "Autoloads"         "org:r-lib"         "package:base"     

If a newly loaded package has functions with the same name as a previously loaded package, you get a warning. Here is what I get when I load dplyr

> library(dplyr)

Attaching package: ‘dplyr’

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

    filter, lag

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

    intersect, setdiff, setequal, union

The first part of the warning says that the filter and lag functions from the stats package are masked. That means the calling filter() results in the function from dplyr being used, because dplyr is now in the second place in the stack of packages, not the function with the same name in stats. To use the filter function from stats, you would have to write stats::filter().

1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.