[Rd] reverse object creation

Bo Werth bo.werth at gmail.com
Fri Oct 9 11:55:08 CEST 2015


Dear all,

this is my first message to this mailing list - please advise if it is not
the right place for the subject

I've been using R very intensively the last 3-4 years and one of the most
tedious tasks is modification of lookup or conversion tables

So far, I have not found functions that create the commands for creating
objects (vectors, data frames) based on the objects themselves - i.e. to
reverse-engineer them.

Here are my suggestions:

c_rev <- function(x) cat(paste0('c("', gsub(', ', '", "', toString(x)),
'")\n'))

df_rev <- function(x) {
    X <- apply(x, 1,
               function(x) {
                   paste0('c(',
                          paste0(shQuote(x), collapse = ", "),
                          ')'
                          )
               }
               )
    command <- paste0(
        'rbind.data.frame(',
        paste0(
            X,
            collapse = ",\n"),
        ')')
    return(cat(command, "\n"))
}

Bo

---
bowerth.github.io

	[[alternative HTML version deleted]]



More information about the R-devel mailing list