Make enter the names of its variables to the user (R)

Hi! I want to know if it's possible to make sear to the user of a program the name of few variable to automate as much as possible the execution of a R program.

I sont understand.
What is unclear? Can you give example?
What sort of automation do you have in mind?

To run a certain package, I need to prepare my data to meet the expectations of that package. But the name of the variables can change according to the files imported so that the preparation is as autonomous as possible and that a user does not need to manipulate the R code too much. I don't know if it would be possible to ask the user to enter these variables names, to be able to reuse them later, much like an input would do in Python. I hope I am clear enough :sweat_smile:

one simple way is to declare are the top of your script a lookup for the new names that need map to old/expected names.

library(dplyr)
name_lkup <- c("old1"="new1",
               "old2"="new2")

(new_df <- data.frame(new1=123,
                   new2="xyz"))
(old_df <- rename(new_df,
                  all_of(name_lkup)))

#then run process on old_df

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.