So, I got 2 functions, one of which can iterate over data frames, and the other for one vector. Using parts of the Adrian solution [thanks!]:
hist_dataframe <- function(variable, col ="gold1", ...) { stopifnot(colName %in% colnames(df)) variable = df[,colName] stopifnot(length (variable) >1 ) plotname = paste(substitute(df),'__', colName, sep="") FnP = paste (getwd(),'/',plotname, '.hist.pdf', collapse = "", sep=""); print (FnP) hist (variable, main = plotname) dev.copy2pdf (file=FnP ) }
And the one that for simple vectors remains the same as in Q.
source share