我对专有数据进行了一些数据争论,并且在对变量名称或类型进行更改后,spec()
没有更新问题。我将mtcars
作为我体验的一个例子。任何人都可以让我知道为什么会这样,以及如何让它更新?
library(tidyverse)
# use read_csv to read in original file
mtcars_orig <- read_csv(readr_example("mtcars.csv"))
spec(mtcars_orig) # check variable types
# make work file
mtcars_work <- mtcars_orig
# rename mpg variable
mtcars_work <- rename(mtcars_work, m_p_g = mpg)
str(mtcars_work) # m_p_g name updates
spec(mtcars_work) # mpg name doesn't update
# change cyl to character type
mtcars_work$cyl <- as.character(mtcars_work$cyl)
str(mtcars_work$cyl) # variable type updates
spec(mtcars_work) # variable type doesn't update