site

files for beauhilton.com
git clone https://git.beauhilton.com/site.git
Log | Files | Refs

2099-03-07-on-blog-tone.md (6301B)


      1 ---
      2 layout: post
      3 title: "On blog tone"
      4 toc: true
      5 image: https://source.unsplash.com/OfMq2hIbWMQ
      6 tags:
      7   - carnivalesque
      8   - writing
      9 ---
     10 
     11 ## What's a blog for, anyway?
     12 
     13 
     14 
     15 The main problem with the approach I outlined was how to get those nicely updated paragraphs into the document you are sharing with colleagues.
     16 
     17 Medicine, in particular, seems wed to Microsoft Word documents for manuscripts. Word does not have a great way to include text from arbitrary files, forcing the physician-scientist to manually copy and paste those beautifully automated paragraphs. As I struggled with this, I thought (here cue Raymond Hettinger), "There must be a better way."
     18 
     19 Turns out that better way exists, and it is R Markdown.
     20 
     21 Though I was at first resistant to learning about R Markdown, mostly because I am proficient in Python and thought the opportunity cost for learning R at this point would be too high, as soon as I saw it demoed I changed my tune. Here's why.
     22 
     23 ## Writing text
     24 - R Markdown is mostly markdown.
     25 	- Markdown is by far the easiest way to write plaintext documents, especially if you want to apply formatting later on without worrying about the specifics while you're writing (e.g. `#` just specifies a header - you can decide how you want the headers to look later, and that styling will automatically be applied).
     26 	- Plaintext is beautiful. It costs nearly nothing in terms of raw storage, and is easy to keep within a version control system. Markdown plaintext is human-readable whether or not the styling has been applied. Your ideas will never be hidden in a proprietary format that requires special software to read.
     27 	- I had been transitioning to writing in Markdown anyway, so +1 for R Markdown.
     28 - R Markdown is also a little LaTeX.
     29 	- LaTeX is [gorgeous](https://tex.stackexchange.com/questions/1319/showcase-of-beautiful-typography-done-in-tex-friends) and wonderful, the most flexible and expressive of all the typesetting tools (though not as fast as our old friend Groff...). It also has a steeper learning curve than Markdown, and is not so pretty on the screen in its raw form. R Markdown lets you do the bulk of your work in simple Markdown, then seamlessly invoke LaTeX when you need something a little fancier.
     30 - R Markdown is also a little HTML.
     31 	- HTML is also expressive, and can be gorgeous and wonderful. It is a pain to write. As with LaTeX, you can simply drop in some HTML where you need it, and R Markdown will deal with it as necessary.
     32 - R Markdown is academic-friendly.
     33 	- Citations and formatting guidelines for different journals are the tedious banes of any academic's existence. R Markdown has robust support for adding in citations that will be properly formatted in any desired style, just by changing a tag at the top of the document. Got a rejection from Journal 1 and want to submit to Journal 2, which has a completely different set of citation styles and manuscript formatting? NBD.
     34 
     35 ## Writing code
     36 R Markdown, as the name implies, can also run R code.
     37 Any analysis you can dream of in R can be included in your document, and you can choose whether you want to show the code and its output, the output alone, or the code alone.
     38 People will think you went through all the work of making that figure, editing it in PowerPoint, screenshotting it to a .png, then dropping that .png file into your manuscript, but the truth is...
     39 you scripted all of that, so the manuscript itself made the .png and included it where it needed to go.
     40 
     41 R Markdown is by no means restricted to R code.
     42 This is the killer app that won me over.
     43 Simply by specifying that a given code block is Python,
     44 and installing a little tool (`reticulate`) that allows R to interface with Python,
     45 I can run arbitrary Python code within the document and capture the output however I want.
     46 That results paragraph? Sure.
     47 Fancy images of predictions from my machine learning model? But of course.
     48 
     49 If you don't want to use any R code ever, that's fine. R Markdown doesn't mind.
     50 Use SAS, MATLAB (via Octave), heck, even bash scripts - the range of language support is fantastic.
     51 
     52 ## Working with friends
     53 R Markdown can be compiled to pretty much any format you can dream of.
     54 My current setup simultaneously puts out an HTML document (that can be opened in any web browser), a PDF (because I love PDFs), and (AND!) a .docx Word file,
     55 all beautifully formatted, on demand, whenever I hit my keyboard shortcut. I can preview the PDF or HTML as I write, have a .docx to send to my PI, and life is good.
     56 
     57 Also, because you can write in any programming language, you can easily collaborate between researchers that are comfortable in different paradigms.
     58 You can pass data back and forth between your chosen languages (for me, R and Python),
     59 either directly or by saving intermediate data to a format that both languages can read.
     60 
     61 ## Automating tasks
     62 Many analyses and their manuscripts, especially if they use similar techniques (e.g. survival modeling), are rather formulaic.
     63 Many researchers have scripts they keep around and tweak for new analyses revolving around the same basic subject matter or approach.
     64 With R Markdown, your entire manuscript becomes a runnable program, further automating the boring parts of getting research out into the open.
     65 
     66 One of the [first introductions](https://www.youtube.com/watch?v=MIlzQpXlJNk) I had to R Markdown shared the remarkable idea of setting the file to run on a regular basis,
     67 generating a report based on any updated data,
     68 and then sending this report to all the interested parties automatically.
     69 While much academic work could not be so fully automated, parts of it certainly can be.
     70 
     71 Perhaps your team is building a database for outcomes in a given disease, and has specified the analysis in great detail beforehand.
     72 One of my mentors gives the advice that in any project proposal you should go as far as to mock up the results section,
     73 including all figures,
     74 so you make sure you are collecting the right data.
     75 If this was done in an R Markdown document rather than a simple Word document,
     76 you could have large parts of the template manuscript
     77 become the real manuscript as the database fleshes out over time.
     78 Then when it's done, look over the data, make additions and subtractions as needed,
     79 write the discussion sections, and send it in.