在控制台与 R markdown 单元格中 运行 时调度不同的打印方法?

Different print method dispatched when running in console vs R markdown cell?

当我在控制台和 R markdown 文档中 运行 以下代码时,我看到正在调度不同的方法。这是一个错误,还是代码的方式 运行 影响方法调度?

library(sloop)
library(tidyverse)

df <- tibble(x=rnorm(5),
               y=rnorm(5))

sloop::s3_dispatch(print(df))

运行 R Markdown 代码单元中的代码(在 RStudio 中)

运行控制台中的代码

RStudio 正在覆盖笔记本中的 print.tbl_df。代码 here.

在 R 笔记本中:

getAnywhere(print.tbl_df)
#> 2 differing objects matching ‘print.tbl_df’ were found
#> in the following places
#>   registered S3 method for print
#>   namespace:tibble
#> Use [] to view one of them

getAnywhere(print.tbl_df)[1]
#> function (x, ...) 
#> {
#>     o <- overrideMap(x, options)
#>     if (!is.null(o)) {
#>         overridePrint(o$x, o$options, o$className, o$nRow, o$nCol)
#>     }
#> }
#> <bytecode: 0x7fb2bdf8fd48>
#> <environment: 0x7fb2bd9567e8>
#> attr(,".rs.S3Override")
#> [1] TRUE

在普通的 R 控制台中:

getAnywhere(print.tbl_df)
#> A single object matching ‘print.tbl_df’ was found
#> It was found in the following places
#>   namespace:tibble
#> with value
#> 
#> function (x, ..., n = NULL, width = NULL, n_extra = NULL) 
#> {
#>     NextMethod()
#> }
#> <bytecode: 0x7fb2b77d7040>
#> <environment: namespace:tibble>