Putting R codes on MS word document
4
3
Entering edit mode
5.2 years ago
babasaraki ▴ 50

Hello everyone,

Any idea on how I can paste R codes into a word document, please? I used DESeq2 and some other packages in R for RNA-Seq and enrichment analyses. I want to put some of the R codes into a word document as it appears in R console. So, I am wondering how to do that.

I appreciate your usual support.

Thank you

R RNA-Seq sequencing • 18k views
ADD COMMENT
0
Entering edit mode

Just change the font to a monospaced font like courier, and paste the code?

ADD REPLY
0
Entering edit mode

Thank you Dr. Joe, will give it a try.

ADD REPLY
0
Entering edit mode

Code in a Word document looks unprofessional, in my opinion. You may consider instead creating a R markdown file and then knitting to PDF? Edit: or, at least, do what jrj.healey suggests and use a different font so that the code stands out.

ADD REPLY
1
Entering edit mode

Thank you so much Professor Kevin for the more enlightening on this. Will check onto it and I do appreciate your usual support. I learnt from your wealth of knowledge and experience.

ADD REPLY
6
Entering edit mode
5.2 years ago

You can write your whole analysis in Markdown including your code blocks, and then render it into Word and back using redoc: https://github.com/noamross/redoc

ADD COMMENT
0
Entering edit mode

Another important clues here. Thank you so much Sir.

ADD REPLY
4
Entering edit mode
5.2 years ago

RStudio also supports the generation of Word documents; all you'd have to do is to copy and paste the code into an Rmarkdown document after installing RStudio and then using the knit button option for generating a Word document.

https://rmarkdown.rstudio.com/

ADD COMMENT
0
Entering edit mode

Thank you Professor Friederike for your usual support whenever I made question. I gladly appreciated.

ADD REPLY
3
Entering edit mode
5.2 years ago
zx8754 12k

If reproducibility is not an issue and we just want to present the codes with pretty formatting, then we could convert formatted code into an image, for example see Carbon website:

ADD COMMENT
0
Entering edit mode

Thank you Dr for sharing. Will have a look and learn from it.

ADD REPLY
2
Entering edit mode
5.2 years ago
Tom K ▴ 20

R has a history() command that will return the commands you’ve run to the console or a text file. I recommend working in RStudio where you can write a “script” and run lines from it so what you did is saved as you go.

It’s your thesis or paper so up to you but I’d consider digital supplementary data if you have a lot of code (GitHub repo or CD). If anyone wants to reproduce the code then it will be easier for them as well. Of course, check with your supervisor and collaborators to make sure they’re okay with releasing this. An R package to run any new functions you’ve made would also be helpful but this is more effort so isn’t always expected.

Make sure to list the versions of the packages you used as well from sessionInfo() and cite appropriately. Setting up the right packages is just as important for reproducibility.

ADD COMMENT
0
Entering edit mode

Thank you Dr. Tom for this insightful suggestion and comments

ADD REPLY

Login before adding your answer.

Traffic: 1725 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6