I am learning R and wondering if Lubridate should post a "union" masking message from dplyr.
With dplyr loaded before lubridate, I get the error message: arrangement:
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 library(lubridate) df1 <- data.frame(c1 = "a", c2 = 1) df2 <- data.frame(c1 = "a", c2 = 2) union(df1, df2) %>% arrange(c1) Error in UseMethod("arrange_") : no applicable method for 'arrange_' applied to an object of class "list"
The union seems to return a list instead of data.frame, and then organize it:
str(union(df1, df2)) List of 3 $ : Factor w/ 1 level "a": 1 $ : num 1 $ : num 2
In the end, I decided that lubridate has a function "union", which is apparently called instead of dplyr "union". In particular, the dplyr "union" request does the trick:
str(dplyr::union(df1, df2)) 'data.frame': 2 obs. of 2 variables: $ c1: Factor w/ 1 level "a": 1 1 $ c2: num 1 2 dplyr::union(df1, df2) %>% arrange(c1) c1 c2 1 a 1 2 a 2
Or, if lubridate is loaded first, all is well. Here is an example (after restarting RStudio):
library(lubridate) library(dplyr) Attaching package: 'dplyr' The following objects are masked from 'package:lubridate': intersect, setdiff, union The following objects are masked from 'package:stats': filter, lag The following objects are masked from 'package:base': intersect, setdiff, setequal, union df1 <- data.frame(c1 = "a", c2 = 1) df2 <- data.frame(c1 = "a", c2 = 2) union(df1, df2) %>% arrange(c1) c1 c2 1 a 1 2 a 2
The key saw that dplyr was masking the โunionโ from lubridate (although the first key was the message โnot applicable methodโ, but I did not know what was happening - I would be next time). However, I expected that when lubridate was loaded after dplyr, a similar message would be posted indicating that lubridate would mask the "union" from dplyr. Is there a reason why such a message did not appear? Maybe something I need to include in my setup?
I am using RStudio version 0.99.489, R version 3.2.3, dplyr version 0.4.3 and lubridate version 1.5.0 for Windows 7.