When column names have > (greater than) or < (lesser than) sign and I try to join on these columns, the column with the sign gets trimmed and I get an error like this one:
Error in colnamesInt(x, names(on), check_dups = FALSE) : argument specifying columns specify non existing column(s): cols[1]='COLUMN WITH'
Code to reproduce the issue
library(data.table)
table_a <- data.table(
`COLUMN WITH >FAILS` = character(),
BLA = integer(),
BLO = integer()
)
table_b <- data.table(
`COLUMN WITH >FAILS` = character(),
BLA = integer(),
BLI = integer(),
BLU = integer()
)
on = setdiff(names(table_a), c("BLA", "BLU", "BLO"))
table_a[table_b, on = on]
My scrappy workaround was to replace the special character before the join and put the original column name after the join, it works but doesn't look very elegant. I don't know if that is a known issue, I haven't found any documentation about this. Can you think of a better way of solving this?
Backticks inside quotes allow to use reserved symbols in the join :
table_a[table_b, on = "`COLUMN WITH >FAILS`"]
Empty data.table (0 rows and 6 cols): COLUMN WITH >FAILS,BLA,BLO,i.BLA,BLI,BLU
Or more generally:
table_a[table_b, on = paste0("`",on,"`")]
Empty data.table (0 rows and 6 cols): COLUMN WITH >FAILS,BLA,BLO,i.BLA,BLI,BLU
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.