作者coo20819 (Mike)
看板R_Language
标题Re: [问题] 函数的output排版,与一些相关问题
时间Mon Dec 23 13:51:33 2013
在此先非常感谢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
1F:推 Wush978:一种方法是你定义一个S3物件来做到类似的事情 12/23 14:37
2F:→ Wush978:像lm物件这样。你回传的物件,多设定他的"class", ex: 12/23 14:37
3F:→ Wush978:class(retval) <- "xxx" 12/23 14:37
4F:→ Wush978:然後定义所谓的print.xxx 12/23 14:37
5F:→ Wush978:把cat的部分放在print.xxx里面 12/23 14:38
6F:→ andrew43:我的回文和Wush板主是同样的意思。 12/23 14:43
7F:→ coo20819:是!这是我想要的!!!非常感谢上面两位大力帮忙 12/23 16:58