在R中,是否有类似于Perl中的
qw
的“引用单词”运算符?qw
是一个引用运算符,它允许您创建一个带有引号的项目列表,而不必逐个引用每个项目。以下是没有使用qw
(即使用大量引号和逗号)的方法:#!/bin/env perl
use strict;
use warnings;
my @NAM_founders = ("B97", "CML52", "CML69", "CML103", "CML228", "CML247",
"CML322", "CML333", "Hp301", "Il14H", "Ki3", "Ki11",
"M37W", "M162W", "Mo18W", "MS71", "NC350", "NC358"
"Oh7B", "P39", "Tx303", "Tzi8",
);
print(join(" ", @NAM_founders)); # Prints array, with elements separated by spaces
这里做相同的事情,但使用 qw
更加简洁:
#!/bin/env perl
use strict;
use warnings;
my @NAM_founders = qw(B97 CML52 CML69 CML103 CML228 CML247 CML277
CML322 CML333 Hp301 Il14H Ki3 Ki11 Ky21
M37W M162W Mo18W MS71 NC350 NC358 Oh43
Oh7B P39 Tx303 Tzi8
);
print(join(" ", @NAM_founders)); # Prints array, with elements separated by spaces
我已经搜索过了,但没有找到任何东西。
stringi::stri_split_boundaries
或stri_extract_*_words
这样的东西。但对于那些从未使用过 Perl 的人来说,了解qw()
究竟是做什么的会很好。 - Rich Scrivenqw
的建议!刚刚进行了编辑。 - Christopher Bottoms