gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 17:23:44 24 4
gpt4 key购买 nike

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

library(sloop)
library(tidyverse)

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

sloop::s3_dispatch(print(df))

在 R Markdown 代码单元中运行代码(在 RStudio 中) Running the code in RStudio code cell

在控制台中运行代码 Running the code in console

最佳答案

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>

关于r - 在控制台与 R markdown 单元中运行时调度的不同打印方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64702200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com