format_call <- function(g) {
stopifnot(is.call(g))
ls <- as.list(g)
ls[] <- lapply(ls, deparse1)
paste0(
ls[[1]], "(\n ",
paste0(names(ls)[-1], " = ", ls[-1], collapse = ",\n "),
"\n)"
)
}
print_call <- function(g) {
cat(format_call(g), "\n", sep = "")
}
g <- call("data.frame", a = 1, b = 2, row.names = c("a", "b"))
print_call(g)
#> data.frame(
#> a = 1,
#> b = 2,
#> row.names = c("a", "b")
#> )
format_call(g)
#> [1] "data.frame(\n a = 1,\n b = 2,\n row.names = c(\"a\", \"b\")\n)"
Created on 2023-10-18 with reprex v2.0.2
Created on 2023-10-18 with reprex v2.0.2