using a function to rename a tibble

How can I set the name of the tibble I want to create as an argument to my function?
I want the function to be part of a package.

a <- dplyr::tibble(x = 1)

rename_object <- function(in_df, out_df) {
  out_df <- in_df

rename_object(in_df = a, out_df = b)
a <- dplyr::tibble(x = 1)

rename_object <- function(in_df, out_df,envir=.GlobalEnv) {
  # browser()
  ie <-enquo(in_df)
  oe <- enquo(out_df)
  assign(x = as_name(oe),
         value = in_df,
         envir = envir)
  remove(list = as_name(ie),envir =envir)

rename_object(in_df = a, out_df = b)

Thanks very much. I want to save out_df in data as part of a package eg instead of assign() my function contains something like
usethis::use_data(out_df, overwrite = TRUE, internal = FALSE )

How do I refer to out_df in use_data()?

Explanation: My package has a function which imports data for each year into a tibble. I want to include the year in the name of tibble. The package then uses other functions in the package to report on the data.

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.