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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
