看板 R_Language 關於我們 聯絡資訊
在此先非常感謝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 ``` 希望您能理解,非常感謝您! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.231.53.159
Wush978:一種方法是你定義一個S3物件來做到類似的事情 12/23 14:37
Wush978:像lm物件這樣。你回傳的物件,多設定他的"class", ex: 12/23 14:37
Wush978:class(retval) <- "xxx" 12/23 14:37
Wush978:然後定義所謂的print.xxx 12/23 14:37
Wush978:把cat的部分放在print.xxx裏面 12/23 14:38
andrew43:我的回文和Wush板主是同樣的意思。 12/23 14:43
coo20819:是!這是我想要的!!!非常感謝上面兩位大力幫忙 12/23 16:58