Option 1
Maybe you can use setdiff:
DT <- data.table(A = 1:2, B = 3:4, X = 5:6)
DT
# A B X
# 1: 1 3 5
# 2: 2 4 6
setcolorder(DT, c("X", setdiff(names(DT), "X")))
DT
# X A B
# 1: 5 1 3
# 2: 6 2 4
Option 2
Using a modified version of your approach:
setcolorder(DT, c("X", names(DT)[1:(length(DT)-1)]))
or
setcolorder(DT, c(length(DT), 1:(length(DT)-1)))
Why the error in your approach? You were trying to include both column names and numeric column indices. Use one or the other, but not both.
Option 3
I've written a function called moveme (which for the time being you can find at this Gist or at my blog). You enter a string of "move" commands, separated by semicolons. This lets you shuffle around your columns pretty flexibly:
DT <- data.table(matrix(1:20, ncol = 10, dimnames = list(NULL, LETTERS[1:10])))
DT
# A B C D E F G H I J
# 1: 1 3 5 7 9 11 13 15 17 19
# 2: 2 4 6 8 10 12 14 16 18 20
setcolorder(DT, moveme(names(DT), "E, F first; B last; H, I before G"))
# DT
# E F A C D H I G J B
# 1: 9 11 1 5 7 15 17 13 19 3
# 2: 10 12 2 6 8 16 18 14 20 4