a combination of dput and capture.output ought to work. For example:
some_function <- function(x){
if (TRUE){
x_str <- capture.output(dput(x))
stop(glue::glue("Invalid subset {x_str}"))
}
}
some_function(letters[1:5])
Error in some_function(letters[1:5]) :
Invalid subset c("a", "b", "c", "d", "e")
As an alternative, I have a strong preference for the checkmate package. Your function might look something like this with checkmate
other_function <- function(x){
checkmate::assert_subset(x = x,
choices = letters)
}
other_function(c("a", 1, "c"))
Error in other_function(c("a", 1, "c")) :
Assertion on 'x' failed: Must be a subset of
{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}.