Why data.table::setnames acts on multiple dataframes while I'm specifying just one?

Viewed 39

As you can read in the title I'm wondering why data.table::setnames acts on multiple dataframes while I'm specifying just one. See attached code below:

library(data.table)

# create dataframe
df <- data.frame(col_1 = c(1:9), col_2 = letters[1:9])

# craeate dataframe copy
df_copy <- df

# check names
names(df)
names(df_copy)

# change dataframe "df" names
data.table::setnames(x = df, old = c("col_1", "col_2"), new = c("col_a", "col_b"))

# check names
names(df)
names(df_copy)

As you can see, I'm specifying just dataframe df for argument x in function setnames but after running code also the names of dataframe df_copy result in changes. It's seems assign operator <- is acting as a dynamic join instead of assigning a copy of df to df_copy. Anyone can help me understanding why?

0 Answers
Related