Another important clues here. Thank you so much Sir.
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
4 answers
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
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.
Thank you Professor Friederike for your usual support whenever I made question. I gladly appreciated.
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:
Thank you Dr for sharing. Will have a look and learn from it.
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.
Thank you Dr. Tom for this insightful suggestion and comments
Log in to answer this question.
Just change the font to a monospaced font like courier, and paste the code?
Thank you Dr. Joe, will give it a try.
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.
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.