使用 RStudio 文本编辑器将多行转换为单行

发布于 2025-01-13 21:54:13 字数 314 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

浮光之海 2025-01-20 21:54:14

@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.

娇妻 2025-01-20 21:54:14

正如 @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 use vector_paste() or use the keyboard shortcut, which is ctrl+alt+shift+v.

enter image description here

You can read about some of the other functions and shortcuts (e.g., paste as vertical vector) at Typical Datapasta Usage with Rstudio.

携君以终年 2025-01-20 21:54:14

RStudio 具有查找/替换功能。您可以将换行符 \n 替换为空格 以达到此效果。确保选中“正则表达式”框才能正常工作。

输入图片此处描述

RStudio has a find/replace feature. You can replace new line characters \n with spaces for this effect. Make sure you have the "regex" box checked for it to work.

enter image description here

鱼窥荷 2025-01-20 21:54:14

您可以使用 dput:

dput(c(
"097",
"085",
"041",
"055"
))
#> c("097", "085", "041", "055")

还可以通过安装 styler 包来设置代码格式化插件,将其绑定到键盘快捷键。

You can use dput:

dput(c(
"097",
"085",
"041",
"055"
))
#> c("097", "085", "041", "055")

It is also possible to set-up a code formatting add-in that you can bind to keyboard shortcuts by installing the styler package.

心碎无痕… 2025-01-20 21:54:13

本身不是一个自动化解决方案,但很多人不知道 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:

enter image description here

Also very handy for adding commas or closing parentheses to multiple lines at once.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文