Glad to hear you like it!
@ Karthik yeah, it sounds like you follow me - in an ideal world, you’d end up with real-time changes in sync (in both directions) between Google Doc and the Rmarkdown, but (for now at least) the ‘triggers’ available for Apps Script are limited to time repeats, at most every hour.
This suggests to me either there’s some other way to use this API, google.script.run
client-side API looks about right.
I’m sure it’s technically possible to set up updating with every edit, but I’m not clear on that so wouldn’t focus on it at this point. Note that every change of a Google Drive file is saved automatically (the document constantly displays “changes saved in Drive”) so it’s possible.
I see it converting to md, and then (I’m thinking of RStudio here) the changes are visible in real-time as for when you edit a local file with a text editor. So there’d need to be some framework to update a local reference to the gdoc file - there’s no such thing as a local gdoc file to “retrieve” really, it’s just JSON containing a reference URL to the document as seen by cat
ing it and e.g. the picture of my screen on this page, where I set up local ‘storage’ of gdocs in the same format they’re stored on Chrome OS.
Long story short any interaction would be through web interfaces not file storage. So the act of sending back to Drive would have to be through an API either a good one in R or the one being worked on by Google apps developers (which I think must surely be a good source of ready-to-roll code?).
So the Google Doc should contain some way of delineating code chunks as in Rmarkdown (as unobtrusive as possible but as I’ve noted there’s no code block).
The Code pretty GDocs add-on by Ian Kilpatrick (@bfgeek on GitHub/Twitter) interprets single-cell tables as code blocks for (implicit/assumptive) syntax highlighting - perhaps he could be persuaded to open source it and we could use it as a starting point to access single-cell tables to interpret them as code chunks.
By default, anything in such a single-cell table would be stuck inside a (non-chunk) code block:
```r
```
but then anything with some switch could go in an {r}
knitr-usable chunk and with more switches the full scope of chunks could be accessed (including changing code language, eval=TRUE
and all of that). Syntax highlighting would be the icing on the cake, and there are lots of Javascript libraries to do so (and lots of JS devs who might chip in their expertise).
The YAML should be generated through UI rather than being visible in the document - it’s metadata. I’m sure there’ll be facilities to do so in the “UI” API or however Google’s implemented it (got a feeling I read they deprecated UI but would have to check up on it all).
I’ve written a Chrome extension before and it seems the same kind of setup - Javascript more or less, but with all their own commands and very tight but well-documented syntax, tons of examples because it’s an active area.
TeX doesn’t have much of a place here as I’m seeing it, but I’m sure it could find some way in at a later stage. Given all of that there’d be pretty good preservation of all of Rmarkdown’s features(?)
I’ll ask Ian if he’ll take a look at this thread and might consider open sourcing the add-on.
@ Oliver httr and oauth is probably how this would be handled… it’ll involve looking up how to access Google APIs and interpret the objects of the document (online), outputting a string with newlines to be saved to disk as Rmarkdown. Given the existing script I wouldn’t expect it to be too hard.
@ Noam like I say there’s no actual file - just a reference JSON with URL and id (the URL contains the ID so even that’s pretty redundant). The file on disk would be the Rmd, so perhaps we’re better of starting to think of the downloading as being to Rmd… conceptually it makes it a bit clearer to not be thinking about “downloading a Google doc” perhaps. The string that comes out of the online API is markdown - there’s not really anything else to talk about saving.
Edit Just been blocked from posting this comment twice due to the link…? Chrome webstore, GitHub and Twitter are all that are here. Removed them now… Also not letting me use more than 2 links / user mentions… or use an image in my post I vote to go back to GitHub issues or a Google group or something