You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I came across some potentially strange behaviour of arrange when using the desc function with the .data pronoun. The line below is throwing the following error: "Error: Can't subset .data outside of a data mask context."
arrange(.data$SID, desc(.data$prop))
If desc() is not used within arrange() it works fine with the .data pronoun. Also, this issue only happens when using dtplyr but is working fine with dplyr. Here is a reproducible example:
library(dtplyr)
library(dplyr)
x<-data.frame(SID=1:100,
train= sample(c(0,1), 1000, replace=TRUE))
x<-dtplyr::lazy_dt(x, key_by="SID")
# KO - does not work and generates:# Error: Can't subset `.data` outside of a data mask context.tb<-x %>%
group_by(.data$SID, .data$train) %>%
summarize(prop= n()) %>%
mutate(rs= sum(.data$prop)) %>%
ungroup()%>%
mutate(prop=.data$prop/.data$rs) %>%
select(-.data$rs) %>%
filter(!is.na(.data$train)) %>%
filter(.data$prop>=0.5) %>%
group_by(.data$SID) %>%
arrange(.data$SID, desc(.data$prop)) %>%
slice(1) %>%
ungroup() %>%
select(-.data$prop) %>%
as.data.frame()
# OK - runs fine if the .data pronoun is removed tb<-x %>%
group_by(.data$SID, .data$train) %>%
summarize(prop= n()) %>%
mutate(rs= sum(.data$prop)) %>%
ungroup()%>%
mutate(prop=.data$prop/.data$rs) %>%
select(-.data$rs) %>%
filter(!is.na(.data$train)) %>%
filter(.data$prop>=0.5) %>%
group_by(.data$SID) %>%
arrange(.data$SID, desc(prop)) %>%
slice(1) %>%
ungroup() %>%
select(-.data$prop) %>%
as.data.frame()
# Also OK to use the .data pronoun but not the desc() functiontb<-x %>%
group_by(.data$SID, .data$train) %>%
summarize(prop= n()) %>%
mutate(rs= sum(.data$prop)) %>%
ungroup()%>%
mutate(prop=.data$prop/.data$rs) %>%
select(-.data$rs) %>%
filter(!is.na(.data$train)) %>%
filter(.data$prop>=0.5) %>%
group_by(.data$SID) %>%
arrange(.data$SID, .data$prop) %>%
slice(1) %>%
ungroup() %>%
select(-.data$prop) %>%
as.data.frame()
# Also works fine when not using dtplyry<-data.frame(SID=1:100,
train= sample(c(0,1), 1000, replace=TRUE))
tb<-y %>%
group_by(.data$SID, .data$train) %>%
summarize(prop= n()) %>%
mutate(rs= sum(.data$prop)) %>%
ungroup()%>%
mutate(prop=.data$prop/.data$rs) %>%
select(-.data$rs) %>%
filter(!is.na(.data$train)) %>%
filter(.data$prop>=0.5) %>%
group_by(.data$SID) %>%
arrange(.data$SID, desc(.data$prop)) %>%
slice(1) %>%
ungroup() %>%
select(-.data$prop) %>%
as.data.frame()
Hello,
I came across some potentially strange behaviour of arrange when using the desc function with the .data pronoun. The line below is throwing the following error: "Error: Can't subset
.data
outside of a data mask context."If desc() is not used within arrange() it works fine with the .data pronoun. Also, this issue only happens when using dtplyr but is working fine with dplyr. Here is a reproducible example:
Session info follows below:
Thanks in advance!
The text was updated successfully, but these errors were encountered: