R語言
toString 位於 base 包(package)。 說明
is.string(x) 正在檢查 x 是否為 “string”,即 length(x) == 1 的 character 向量。
toString()是一個輔助函數format生成說明一個的單個字符串R對象。
用法
is.string(x)
toString(x, ...)
## Default S3 method:
toString(x, width = NULL, collapse=", ", ...)
參數
x |
R要轉換的對象。 |
width |
最大字段寬度的建議。 |
collapse |
連接元素時傳遞給 |
... |
傳入或傳出方法的可選參數。 |
細節
toString 是一個通用函數,可以為其編寫方法:此處僅說明默認方法。大多數方法應遵循 width 參數來指定結果的最大顯示寬度(由 nchar(type = "width") 測量)。
默認方法首先將 x 轉換為字符,然後連接由 collapse 分隔的元素,默認為 ", " 。如果提供了 width 並且不是 NULL ,則默認方法將返回結果的前 width - 4 字符,並附加 ....(如果完整結果將使用超過 width 字符)。
值
is.string() 返回 TRUE 或 FALSE 。
toString(.) 返回 ‘string’,即長度為 1 的 character 向量。
例子
x <- c("a", "b", "aaaaaaaaaaa")
toString(x)
toString(x, width = 8)
is.string(x) # FALSE : a character vector of length 3
is.string(x[1]) # TRUE
is.string("") # TRUE
is.string(NA_character_) # TRUE
is.string(character(0)) # FALSE
stopifnot(!is.string(x), !is.string(character()), is.string("abc"), is.string(x[1]))
作者
Robert Gentleman
也可以看看
相關用法
- R taskCallback 添加或刪除頂級任務回調
- R tilde 波形符運算符
- R try 嘗試允許錯誤恢複的表達式
- R transform 轉換對象,例如 DataFrame
- R textConnection 文本連接
- R tracemem 對象的跟蹤複製
- R traceback 獲取並打印調用堆棧
- R t 矩陣轉置
- R table 交叉表和表格創建
- R tempfile 為臨時文件創建名稱
- R taskCallbackManager 創建R級任務回調管理器
- R typeof 對象的類型
- R taskCallbackNames 查詢當前內部頂級任務回調名稱
- R trace 函數或方法調用的交互式跟蹤和調試
- R timezones 時區
- R tabulate 向量列表
- R tapply 對不規則數組應用函數
- R trimws 刪除前導/尾隨空格
- R file.path 構造文件路徑
- R grep 模式匹配和替換
- R getwd 獲取或設置工作目錄
- R vector 向量 - 創建、強製等
- R lapply 對列表或向量應用函數
- R dump R 對象的文本表示
- R Sys.getenv 獲取環境變量
注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Convert an R Object to a Character String or Test for a String。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
