看板 R_Language 關於我們 聯絡資訊
不確定是不是你要的,但你試試看: square <- function(x) { input <- x output <- x^2 y <- list(input=input, output=output) class(y) <- "square" return(y) } print.square <- function(w){ cat("calling print.square...\n") cat("The square of (", w$input, ") equal to", w$output) } 之後可以得到 tmp <- square(3) # 不會顯示 tmp # 會顯示以下二列 calling print.square... The square of ( 3 ) equal to 9 ※ 引述《coo20819 (Mike)》之銘言: : 在此先非常感謝W大熱心的回答,謝謝! : 我也對 'lm' 這個函數有更深的了解, : 但是我嘗試一下還是無法用出我要的結果... : 我表達能力不是很好,再把問題換種方式表達,希望您能理解 : 目前: : ```r : square <- function(x) { : cat(" It is a test.", "\n") : cat(" The square of (", x, ") equal to", x^2) : } : temp <- square(3) : ``` : ``` : ## It is a test. : ## The square of ( 3 ) equal to 9 : ``` : ```r : temp : ``` : ``` : ## NULL : ``` : 我希望藉由'其他函數',可以像'cat'一樣漂亮排版,但又能使用`invisible`來 : 讓R放棄自動呼叫,變成以下: : ```r : temp <- square(3) : temp : ``` : ``` : ## It is a test. : ## The square of ( 3 ) equal to 9 : ``` : 希望您能理解,非常感謝您! -- http://apansharing.blogspot.com/ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.128.117.75 ※ 編輯: andrew43 來自: 140.128.117.75 (12/23 14:44)
coo20819:是!非常感謝您的範例!!!謝謝 12/23 16:59