使用 RStudio 文本编辑器将多行转换为单行
RStudio 文本编辑器是否有一种简单的自动化方法可以将其转换
c(
"097",
"085",
"041",
"055"
)
为:c("097", "085", "041", "055")
?
其他文本编辑器有答案(例如,此处),但我正在寻找特定于 RStudio 的解决方案。
Does the RStudio text editor have a simple automated way to convert this:
c(
"097",
"085",
"041",
"055"
)
to this: c("097", "085", "041", "055")
?
There are answers for other text editors (e.g., here), but I'm looking for a solution specific to RStudio.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
@jdobres 的多行光标答案就是我的做法,但您还应该了解出色的
datapasta
包,它可以完成您所要求的任务以及更多功能。在我看来,RStudio 的一个非常有用的插件。The multi-line cursor answer from @jdobres is how I'd do it, but you should also be aware of the excellent
datapasta
package, which can do what you're asking and a whole lot more. A very helpful add-in for RStudio, imo.正如 @rdelrossi 所提到的,
datapasta
是一个用于编辑和设置文本/代码样式的有用包。在 Mac 上,一旦安装了软件包(也作为加载项安装),您就可以访问多个键盘快捷键。例如,要将矢量从垂直转换为水平,您可以使用vector_paste()
或使用键盘快捷键,即 ctrl+alt +shift+v。您可以在 Rstudio 的典型 Datapasta 用法。
As mentioned by @rdelrossi,
datapasta
is a helpful package for editing and styling text/code. On Mac, once you install the package (also installs as an add-in), then you have access to several keyboard shortcuts. For example, to convert a vector from vertical to horizontal, you could usevector_paste()
or use the keyboard shortcut, which is ctrl+alt+shift+v.You can read about some of the other functions and shortcuts (e.g., paste as vertical vector) at Typical Datapasta Usage with Rstudio.
RStudio 具有查找/替换功能。您可以将换行符
\n
替换为空格以达到此效果。确保选中“正则表达式”框才能正常工作。
RStudio has a find/replace feature. You can replace new line characters
\n
with spacesfor this effect. Make sure you have the "regex" box checked for it to work.
您可以使用 dput:
还可以通过安装 styler 包来设置代码格式化插件,将其绑定到键盘快捷键。
You can use
dput
:It is also possible to set-up a code formatting add-in that you can bind to keyboard shortcuts by installing the
styler
package.本身不是一个自动化解决方案,但很多人不知道 RStudio 对多行游标的支持。只需按住 Alt(Mac 上的 Option)并拖动多行,然后按几次退格键:
也非常方便一次向多行添加逗号或右括号。
Not an automated solution per se, but many people don't know about RStudio's support for multiline cursors. Just hold Alt (Option on Mac) and drag across multiple lines, then press backspace a few times:
Also very handy for adding commas or closing parentheses to multiple lines at once.