使用看门人 clean_names 保留特定字符
我正在使用 janitor
clean_names()
/make_clean_names()
并希望保留某些字符。我认为 replace
是我应该使用的参数,并且适用于某些情况。例如,我可以用零替换破折号:
> janitor::make_clean_names("x-x", replace = c(`-` = "0"))
[1] "x0x"
但是,似乎没有办法保留破折号(或其他特殊字符):
> janitor::make_clean_names("x-x", replace = c(`-` = "-"))
[1] "x_x"
I am using janitor
clean_names()
/make_clean_names()
and would like to preserve certain characters. I think replace
is the argument I should be using and that works for some cases. For example, I can replace dashes with zeros:
> janitor::make_clean_names("x-x", replace = c(`-` = "0"))
[1] "x0x"
However, there does not seem to be a way to keep dashes (or other special characters):
> janitor::make_clean_names("x-x", replace = c(`-` = "-"))
[1] "x_x"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 make_clean_names 的主要原因之一是返回一个无需使用反引号即可解析的标准名称。当存在非标准字符时,该包使用
_
作为默认替换。因此,即使我们在replace
中提供了一个命名的vector
,它也会在代码中更改为_
,正如文档中所说的顺序操作为一个选项是指定
sep_out
返回感兴趣的字符使用
make_clean_names
保留非标准字符的选项是用唯一的标准字符替换,然后替换稍后的独特字符/单词One of the main reasons to use
make_clean_names
is to return a standard name that can be parsed without having to use backquotes. The package uses_
as default replacement when there is a non-standard character. Therefore, even if we provide a namedvector
in thereplace
, it will be changed in the code to_
as the documentation says the order of operations asAn option is to specify the
sep_out
to return a character of interestAn option to preserve the non-standard character using
make_clean_names
would be to replace with a unique standard character and then replace the unique character/words later