What is the difference between as.tibble(), as_data_frame(), and tbl_df()?

后端 未结 2 752
失恋的感觉
失恋的感觉 2020-12-30 04:21

I remember reading somewhere that as.tibble() is an alias for as_data_frame(), but I don\'t know what exactly an alias is in prog

2条回答
  •  滥情空心
    2020-12-30 04:58

    According to the introduction to tibble, it seems like tibbles supersede tbl_df.

    I’m pleased to announce tibble, a new package for manipulating and printing data frames in R. Tibbles are a modern reimagining of the data.frame, keeping what time has proven to be effective, and throwing out what is not. The name comes from dplyr: originally you created these objects with tbl_df(), which was most easily pronounced as “tibble diff”.

    [...]This package extracts out the tbl_df class associated functions from dplyr.

    To add to the confusion, tbl_df now calls as_tibble, which is the preferred alias for as_data_frame and as.tibble: (Hadley Wickham's comment on the issue, and as_tibble docs)

    > tbl_df
    function (data) 
    {
        as_tibble(data, .name_repair = "check_unique")
    }
    

    According to the help description of tbl_df(), it is deprecated and tibble::as_tibble() should be used instead. as_data_frame and as.tibble help pages both redirect to as_tibble.

    When calling class on a tibble, the class name still shows up as tbl_df:

    > as_tibble(mtcars) %>% class
    [1] "tbl_df"     "tbl"        "data.frame"
    

提交回复
热议问题