[Rd] reverse object creation

Thierry Onkelinx thierry.onkelinx at inbo.be
Fri Oct 9 12:22:26 CEST 2015


Dear Bo,

I think that you are looking for dput()

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2015-10-09 11:55 GMT+02:00 Bo Werth <bo.werth at gmail.com>:

> 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]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]



More information about the R-devel mailing list