print 位於 base 包(package)。 說明
print 打印其參數並以不可見的方式返回它(通過 invisible(x) )。它是一個通用函數,這意味著可以輕鬆地為新的 class 添加新的打印方法。
用法
print(x, ...)
## S3 method for class 'factor'
print(x, quote = FALSE, max.levels = NULL,
      width = getOption("width"), ...)
## S3 method for class 'table'
print(x, digits = getOption("digits"), quote = FALSE,
      na.print = "", zero.print = "0",
      right = is.numeric(x) || is.complex(x),
      justify = "none", ...)
## S3 method for class 'function'
print(x, useSource = TRUE, ...)
參數
| x | 用於選擇方法的對象。 | 
| ... | 傳入或傳出其他方法的進一步參數。 | 
| quote | 邏輯,指示是否應使用引號打印字符串。 | 
| max.levels | 整數,表示一個因子應該打印多少個級別;如果  | 
| width | 僅當  | 
| digits | 有效數字的最小數量,請參閱 | 
| na.print | 字符串(或  | 
| zero.print | 指定如何打印零 ( | 
| right | 邏輯,指示字符串是否應該右對齊。 | 
| justify | 指示字符串是否應左對齊、右對齊或單獨保留的字符,傳遞給  | 
| useSource | 邏輯指示內部存儲的源是否應該用於打印(如果存在),例如,如果  | 
細節
默認方法 print.default 有自己的幫助頁麵。使用methods("print") 獲取print 泛型的所有方法。
print.factor 允許進行一些自定義,也可用於打印 ordered 因子。
print.table 用於打印 table 允許其他自定義。從 R 3.0.0 開始,它僅在表的範圍為 0 的情況下打印說明(如果分類器沒有有效數據,則可能會發生這種情況)。
請參閱 noquote 作為主要用途是特定 print 方法的類的示例。
例子
require(stats)
ts(1:20)  #-- print is the "Default function" --> print.ts(.) is called
for(i in 1:3) print(1:i)
## Printing of factors
attenu$station ## 117 levels -> 'max.levels' depending on width
## ordered factors: levels  "l1 < l2 < .."
esoph$agegp[1:12]
esoph$alcgp[1:12]
## Printing of sparse (contingency) tables
set.seed(521)
t1 <- round(abs(rt(200, df = 1.8)))
t2 <- round(abs(rt(200, df = 1.4)))
table(t1, t2) # simple
print(table(t1, t2), zero.print = ".") # nicer to read
## same for non-integer "table":
T <- table(t2,t1)
T <- T * (1+round(rlnorm(length(T)))/4)
print(T, zero.print = ".") # quite nicer,
print.table(T[,2:8] * 1e9, digits=3, zero.print = ".")
## still slightly inferior to  Matrix::Matrix(T)  for larger T
## Corner cases with empty extents:
table(1, NA) # < table of extent 1 x 0 >
參考
Chambers, J. M. and Hastie, T. J. (1992) Statistical Models in S. Wadsworth & Brooks/Cole.
也可以看看
默認方法 print.default ,以及上述方法的幫助;進一步options,noquote。
對於更多可定製(但麻煩)的打印,請參閱 cat 、 format 或 write 。有關簡單的原型打印方法,請參閱包 tools 中的 .print.via.format 。
相關用法
- R print.default 默認打印
- R print.data.frame 打印 DataFrame
- R prod 向量元素的乘積
- R proc.time R的運行時間
- R prmatrix 打印矩陣,舊式
- R proportions 將表條目表示為邊表的分數
- R pretty 漂亮的斷點
- R pushBack 將文本推回連接
- R paste 連接字符串
- R plot 通用 X-Y 繪圖
- R pipeOp 前向管道操作符
- R polyroot 求實數或複數多項式的零點
- R pos.to.env 將搜索路徑中的位置轉換為環境
- R pmatch 部分字符串匹配
- R parse 解析 R 表達式
- R pcre_config PCRE 的報告配置選項
- R path.expand 展開文件路徑
- R file.path 構造文件路徑
- R grep 模式匹配和替換
- R getwd 獲取或設置工作目錄
- R vector 向量 - 創建、強製等
- R lapply 對列表或向量應用函數
- R dump R 對象的文本表示
- R Sys.getenv 獲取環境變量
- R rank 樣本排名
注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Print Values。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
