当复制/粘贴到Word时如何保留从rstudio的格式? [英] How to preserve formatting from rstudio when copy/pasting to Word?

查看:3801
本文介绍了当复制/粘贴到Word时如何保留从rstudio的格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R,Rstudio和SO都是新手 - 我为任何失礼而提前道歉。

我想在Word 2010中重新编写我的代码, 。脚本是用rstudio编写的,我想在粘贴到Word时保留rstudio的格式。原则上,我喜欢rstudio使用的字体颜色和间距。我发现,当我从SAS粘贴到Word,格式保存,但没有骰子。



我通常会寻找复制特殊/粘贴特殊选项来做到这一点,但我找不到任何。当我尝试将特殊字符粘贴到单词中时,只会显示无格式的文本选项。我宁愿不逐行重新格式化文本,因为我认为它在rstudio中看起来不错。



我想把剧本保存在rstudio中格式,将保存其格式,但我找不到任何方式来做到这一点。有没有人有一个想法,我可能会把这个关闭?

在此先感谢

解决方案

从RStudio的脚本编辑器(有4或5种颜色),或者从RStudio(只有2种颜色)的R控制台(脚本+输出)粘贴,并不完全清楚。 >

如果您正在从控制台粘贴 - 请再次勾选粘贴特殊。应该有一个HTML格式的选项,将做你所需要的(虽然你可能需要调整字体的大小,使一切正常,取决于你的页边距)。

如果您是从脚本编辑器粘贴的,那么使用直接的复制粘贴解决方案就不是那么幸运了。但有一个复制和粘贴和复制和粘贴解决方案...

一个解决方案可以使用 Notepad ++ 。从RStudio,保存您的脚本(扩展名为.R),然后在Notepad ++中打开脚本。 (或从RStudio复制并粘贴到Notepad ++,但确保将文件的语言 - 从语言菜单 - 设置为R)。当您的脚本在Notepad ++中正确突出显示时,请转到插件> NppExport>将HTML复制到剪贴板菜单以复制打开的文件。然后,这可以粘贴到MS Word格式的HTML格式。


New to R, Rstudio, and SO -- my apologies in advance for any faux pas.

I want to reproduce my code in Word 2010 for a homework assignment. The scripts were written in rstudio, and I would like to preserve rstudio's formatting when pasting into Word. Principally, I like the font colors and spacing that rstudio uses. I find that when I paste from SAS to Word, the formatting is preserved, but no dice here.

I would usually look for copy special / paste special options to do this, but I can't find any. When I try to paste special into word, only unformatted text options are presented. I would rather not reformat the text line-by-line, because I think it looks pretty nice in rstudio.

I thought of trying to save the script in rstudio to some format that would preserve its formatting, but I couldn't find any way to do this. Does anyone have an idea of how I might pull this off?

Thanks in advance

解决方案

It's not totally clear whether you are pasting from RStudio's script editor (which has some 4 or 5 colors) or from the R console (script + output) within RStudio (which only has 2 colors).

If you are pasting from the console--please check "Paste special" again. There should be an option for "HTML Format" that will do what you need (though you may need to resize the font to make everything fit properly depending on your page margins).

If you are pasting from the script editor, then you're out of luck with a direct copy-and-paste solution. But there is a copy-and-paste-and-copy-and-paste solution...

One solution could be to use Notepad++. From RStudio, save your script (with a ".R" extension) then open the script in Notepad++. (Or copy and paste from RStudio to Notepad++, but make sure you set the file's language--from the "Language" menu--to R). When your script is correctly highlighted in Notepad++ go to the "Plugins > NppExport > Copy HTML to clipboard" menu to copy the open file. This can then be pasted into MS Word with HTML format.

这篇关于当复制/粘贴到Word时如何保留从rstudio的格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆