亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何查看函數的源代碼?

如何查看函數的源代碼?

萬千封印 2019-05-27 10:27:59
如何查看函數的源代碼?我想查看一個函數的源代碼,看看它是如何工作的。我知道我可以通過在提示符下鍵入其名稱來打印函數:> tfunction (x) UseMethod("t")<bytecode: 0x2332948><environment: namespace:base>在這種情況下,是什么UseMethod("t")意思?我如何找到實際使用的源代碼,例如:t(1:10)?有沒有當我看到之間的差異UseMethod,當我看到standardGeneric和showMethods,與with?> withstandardGeneric for "with" defined from package "base"function (data, expr, ...) standardGeneric("with")<bytecode: 0x102fb3fc0><environment: 0x102fab988>Methods may be defined for arguments: dataUse  showMethods("with")  for currently available ones.在其他情況下,我可以看到正在調用R函數,但我找不到這些函數的源代碼。> ts.unionfunction (..., dframe = FALSE) .cbind.ts(list(...), .makeNamesTs(...), dframe = dframe, union = TRUE)<bytecode: 0x36fbf88><environment: namespace:stats>> .cbindtsError: object '.cbindts' not found> .makeNamesTsError: object '.makeNamesTs' not found我如何找到.cbindts和.makeNamesTs?一樣的功能?在其他情況下,有一些R代碼,但大多數工作似乎在其他地方完成。> matrixfunction (data = NA, nrow = 1, ncol = 1, byrow = FALSE, dimnames = NULL) {    if (is.object(data) || !is.atomic(data))         data <- as.vector(data)    .Internal(matrix(data, nrow, ncol, byrow, dimnames, missing(nrow),         missing(ncol)))}<bytecode: 0x134bd10><environment: namespace:base>> .Internalfunction (call)  .Primitive(".Internal")> .Primitivefunction (name)  .Primitive(".Primitive")我如何找出該.Primitive功能的作用?同樣,一些函數調用.C,.Call,.Fortran,.External,或.Internal。如何找到這些的源代碼
查看完整描述

3 回答

?
神不在的星期二

TA貢獻1963條經驗 獲得超6個贊

使用debug()函數進行調試時會顯示它。假設您想在t()轉置函數中查看底層代碼。只需輸入't',就不會顯示太多。

>t 
function (x) UseMethod("t")<bytecode: 0x000000003085c010><environment: namespace:base>

但是,使用'debug(functionName)',它揭示了底層代碼,沒有內部。

> debug(t)> t(co2)debugging in: t(co2)debug: UseMethod("t")Browse[2]> debugging in: t.ts(co2)debug: {
    cl <- oldClass(x)
    other <- !(cl %in% c("ts", "mts"))
    class(x) <- if (any(other)) 
        cl[other]
    attr(x, "tsp") <- NULL
    t(x)}Browse[3]> debug: cl <- oldClass(x)Browse[3]> debug: other <- !(cl %in% c("ts", "mts"))Browse[3]> debug: class(x) 
    <- if (any(other)) cl[other]Browse[3]>  debug: attr(x, "tsp") <- NULLBrowse[3]> debug: t(x)

編輯: debugonce()完成相同,而不必使用undebug()


查看完整回答
反對 回復 2019-05-27
  • 3 回答
  • 0 關注
  • 1515 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號