楼主: 
andrew43 (讨厌有好心推文后删文者)   
2013-12-23 14:43:26不确定是不是你要的,但你试试看:
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
: ```
: 希望您能理解,非常感谢您!