Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法直接从tbl_dbi对象中获取字段名称(db_mtcars如下)?
tbl_dbi
db_mtcars
library(RSQLite) library(dbplyr) library(dplyr) con <- dbConnect(RSQLite::SQLite(), ":memory:") dbWriteTable(con, "mtcars", mtcars) db_mtcars <- tbl(con, "mtcars")
是的colnames()
colnames()
> colnames(db_mtcars) [1] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" [11] "carb"
colnames(db_mtcars)是简单的解决方案,DBI::dbListFields(con, "mtcars")是奇特的解决方案。即使names(db_mtcars)失败,两者都可以工作。
colnames(db_mtcars)
DBI::dbListFields(con, "mtcars")
names(db_mtcars)