Skip to content

Commit

Permalink
test measure(pattern,cols) together
Browse files Browse the repository at this point in the history
  • Loading branch information
tdhock committed Apr 12, 2024
1 parent 8262aa7 commit 6294f57
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -3160,8 +3160,13 @@ test(1034, as.data.table(x<-as.character(sample(letters, 5))), data.table(V1=x))
test(1035.0186, melt(DT_missing_l_2, measure.vars=measure(value.name, char, sep="_"), na.rm=TRUE), data.table(char="1", num=1, list=list(1)))
test(1035.0187, melt(DT_missing_l_2, measure.vars=measure(value.name, char, sep="_"), na.rm=FALSE), data.table(char=c("1","2","3"), num=c(1,2,NA), list=list(1,NA,3)))
# measure supports cols arg, #5063
test(1035.0188, melt(DT_missing_l_2, measure.vars=measure(prefix, char, sep="_", cols=c("list_1","list_3"))), data.table(num_1=1,num_2=2,prefix="list",char=c("1","3"),value=list(1,3)))
test(1035.0189, melt(DT_missing_l_2, measure.vars=measure(value.name, char, sep="_", cols=c("list_1","list_3"))), data.table(num_1=1,num_2=2,char=c("1","3"),list=list(1,3)))
lcols = c("list_1","list_3")
expected_without_value = data.table(num_1=1,num_2=2,prefix="list",char=c("1","3"),value=list(1,3))
test(1035.0188, melt(DT_missing_l_2, measure.vars=measure(prefix, char, sep="_", cols=lcols)), expected_without_value)
test(1035.0189, melt(DT_missing_l_2, measure.vars=measure(prefix, char, pattern="(.*)_(.*)", cols=lcols)), expected_without_value)
expected_with_value = data.table(num_1=1,num_2=2,char=c("1","3"),list=list(1,3))
test(1035.0190, melt(DT_missing_l_2, measure.vars=measure(value.name, char, sep="_", cols=lcols)), expected_with_value)
test(1035.0191, melt(DT_missing_l_2, measure.vars=measure(value.name, char, pattern="(.*)_(.*)", cols=lcols)), expected_with_value)

ans1 = cbind(DT[, c(1,2,8), with=FALSE], variable=factor("l_1"))
ans1[, value := DT$l_1]
Expand Down

0 comments on commit 6294f57

Please sign in to comment.