Saving Reports Generated in R to Evernote

Evernote is my digital filing cabinet. I keep lots of information in it because it is backed up, easy to find and with me wherever I am on all my devices. It is not surprising therefore that I frequently want to store analysis that I carry out in R as an Evernote note.
To produce reports I prefer to use the spin function in Knitr. I love spin because you don’t need a separate markdown file. You can still run the entire script if you want to, because all the markdown formatting instructions just look like comments to regular R. More information on the advantages of spin vs regular markdown here.
Evernote (at least on Windows, I don’t know about other systems) has a wonderful device called an import folder. Any files added to this folder are automatically added to Evernote. In most cases the file is simply attached to a new note. However in the case of html, txt and rtf files, the contents of the file is added to the body of a new note and the file is not attached.  Initially I thought that saving my html document produced by spin to the Evernote import folder would be all I would need to do. Sadly it wasn’t straightforward because it seems that the import folder doesn’t play nicely with local html files –  the more advanced formatting produced by spin is destroyed and images are sometimes not included.
After some experimentation my preferred option (option 6 in the table below) is as follows:
1. Save the output of spin as an html file to Dropbox.
2. Go to Dropbox on the web and open the document (ctrl clicking opens it in a new window without Dropbox clutter). It looks like a regular html web page.
3. Use the Evernote webclipper to save the file to Evernote
Although this is not ideal because there are still some manual steps, it is the only way I could find of achieving goals 1 and 3 in the table below and being able to at least semi-automate the process.
The very short script required to produce the file and take you to Dropbox is as follows, where the R script file referred to (spinexample.R) reproduced below is a properly formatted spin script see here for details . You will need to wait for a few seconds for Dropbox to upload the file to the web before you can see it.
Script that produces report:
library(knitr)
library(rmarkdown)
opts_chunk$set(warning=FALSE,  results = "markup",
              out.width = "100%", echo = TRUE)
setwd("C:/Users/Mike/Documents/R/spin")
render("spinexample.R",
              output_dir = "C:/Users/Mike/Dropbox/R2EN")
browseURL("https://www.dropbox.com/home/R2EN")

The report script (spinexample.R)

#' ---
#' title: "Spin to Evernote Example"
#' author: "Mike"
#' ---
#'
set.seed(1678)
x <- rnorm(1000)
#' Here is the mean. **It's a very important number.**
mean(x)
#' Here is a pretty histogram
#+ echo=FALSE
hist(x)
#' This is the summary of the random numbers
#'
summary(x)
#' Here is a sum
43+27

For reference here is a brief summary of the different approaches I tried. Note that none of these have a full line of crosses. An Evernote note showing the results for options 3, 4 and 6 can be accessed here

Description
Goal 1 – Advanced formatting (highlighted code etc)
Goal 2 – Completely Automatic
Goal 3 – Content forms the body of the note
1
Manually copying and pasting output into Evernote
X
2
Use spin to save an html file to the Evernote import folder
X
X
html must not be self contained (otherwise it leaves out any images)
3
Use spin to save a Word document or pdf document to the Evernote import folder
X
X
4
Use spin to save a rtf document to the Evernote import folder
X
X
Because the the render to rtf doesn’t support advanced formatting anyway you actually see in EN what you get in the rtf document
5
Render as html. Copy and paste content into a gmail. Either webclip or send to Evernote
X
X
6
Preferred option
Use spin to save an html file to Dropbox and then use the webclipper
X
X
Advertisements

One thought on “Saving Reports Generated in R to Evernote

  1. Oh well all good things come to an end. As of mid July 2017 Dropbox have disabled the ctrl-click trick to render the html without clutter. The page with clutter does not work with the webclipper. So it’s the gmail option above or set up a website.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s