我正在编写一个R脚本,并希望定义一个变量,以便在绘图注释中用作文件名的一部分.我以为我会使用strsplit()函数.这是我的代码和输出:
infile = "ACC_1346.table.txt"
x = strsplit(infile, ".")
class(infile)
[1] "character"
class(x)
[1] "list"
str(x)
List of 1
$ : chr [1:18] "" "" "" "" ...
x[[1]]
[1] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
Run Code Online (Sandbox Code Playgroud)
我预计最终的输出是:
[1] "ACC_1346" "table" "txt"
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?
为了避免正则表达式fixed = TRUE在调用中完全使用strsplit
infile = "ACC_1346.table.txt"
x = strsplit(infile, ".", fixed = TRUE)
x
[[1]]
[1] "ACC_1346" "table" "txt"
Run Code Online (Sandbox Code Playgroud)