Is there a standard or or a standard utility to limit the size of
deparse(substitute(.))?
Below please find an example of the problem plus one solution.
If another solution already exists, I might prefer to use it.
Thanks,
Spencer
##
## Problem
##
deparse.x0 <- function(x)deparse(substitute(x))
deparse.a <- do.call(deparse.x0, list(letters))
nchar(deparse.a) # unacceptable
[1] 62 65 4
##
## Better
##
deparse.x <- function(x, maxChar=20){
name.x <- deparse(substitute(x))
nch.x <- nchar(name.x)
name2 <- name.x[nch.x>0]
nch2 <- nch.x[nch.x>0]
if((length(name2)>1)){
name2 <- name2[1]
}
if(nch2[1]>maxChar){
name2 <- paste0(substring(name2, 1, maxChar), '...')
}
name2
}
do.call(deparse.x, list(letters)) # better
[1] "c(\"a\", \"b\", \"c\", \"d\"..."
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.