Technical Notes

In this vignette, some technical details of the trackdown workflow are discussed.

For a general overview of the package, see the trackdown-package help page or vignette("trackdown-workflow") to learn more about the workflow and vignette("trackdown-features") for a detailed description of function arguments and features.

Trackdown Instructions

When uploading (or updating) a file to Google Drive, trackdown adds some simple instructions and reminders on top of the document. For example, in the case of a file named My-Report.Rmd the following instructions are added:

#----Trackdown Instructions----#
This is not a common Document. The Document includes properly formatted Markdown syntax and R code. Please be aware and responsible in making corrections as you could break the code. Limit changes to narrative text and avoid modifying R code.
Please do not remove placeholders of type "[[chunk-<name>]]" or "[[document-header]]"
Once the review is over accept all changes: Tools -> Review suggested edits -> Accept all.
You must not modify or remove these lines, we will do it for you ;)
FILE-NAME: My-Report.Rmd
HIDE-CODE: TRUE
#----End Instructions----#

In particular, the menu option for accepting all changes is pointed out and information about the name of the local file and the selected option for hiding the code is displayed. All these instructions are automatically removed when the document is downloaded so they must not be modified.

Html 2 Pdf

The trackdown package allows uploading the rendered output file (i.e., an HTML or PDF file) together with the main file. This allows collaborators to evaluate the overall layout, including figures and tables, and to add comments to propose and discuss changes. However, only in the case of PDF files, collaborators can add comments directly on the file in Google Drive. This is not possible with HTML files.

When working with HTML output files, trackdown can automatically convert them into PDFs before uploading them to Google Drive. This feature requires that the pagedown package is available. As the pagedown package is not installed as a dependency of trackdown, it has to be installed manually by the user if it is not already available. The function pagedown::chrome_print() is used to convert HTML into a PDF. Note that Google Chrome has to be installed on the user’s system for this conversion operation.

Authentication

Under the hood, the trackdown package uses functions from the googledrive R package (Official Documentation) to manage files transfers to and from Google Drive. However, the googledrive package requires authorization to view and manage a user’s Google Drive files. The first time one uses trackdown, one will be directed to a web browser and asked to sign in to one’s Google account to grant googledrive permission to communicate with Google Drive.

Authentication is managed by the gargle R package (Official Documentation). By default, user credentials are cached in a folder in the user’s home directory, ~/.R/gargle/gargle-oauth, from where they can be automatically refreshed, as necessary. Storage at the user level means that the same token can be used across multiple projects and tokens are less likely to be synced to the cloud by accident. Note that if one is using R from a web-based platform like RStudio Server or Cloud, there will be a variant of this user authentification flow, known as out-of-band auth (“oob”). See help page of googledrive::drive_auth() for further information (link).

It is possible to personalize gargle’s default settings by adding options in the .Rprofile startup file. For example, the preferred Google account and cache folder can be set:

options(
  gargle_oauth_email = "my_email@gmail.com",
  gargle_oauth_cache = "/path/to/folder/that/does/not/sync/to/cloud"
)

See the gargle documentation for further information (link).

The .trackdown folder

When uploading or updating an .Rmd (or .Rnw) file to Google Drive, it is possible to remove the code in the header of the document (YAML header or LaTeX preamble) and code chunks by specifying the argument hide_code = TRUE.

The header code and the code chunks are saved in a hidden folder named .trackdown that will be created in the same location as the uploaded .Rmd (or .Rnw) file. For example, when uploading a file named My-Report.Rmd, two files will be created:

These files are required to automatically restore the header code and all code chunks when the document is downloaded from Google Drive. Consequently, it is important to not delete or move the hidden .trackdown folder. This folder should always be in the same location as the .Rmd (or .Rnw) file.

It is recommended to track the hidden .trackdown folder using Git. This provides an extra layer of safety and a chance to restore the code automatically if the folder was deleted or modified by accident.

Corrupted Files

When editing an .Rmd (or .Rnw) file in Google Docs, it is possible to introduce some syntax errors and break the code so that it is no longer possible to render the document locally after downloading it. This applies to both Markdown (or LaTeX) syntax and R code.

In all cases, using Git to track the .Rmd (or .Rnw) files (or better the whole project) is highly recommended. Git allows restoring previous versions of the document in case of any issues. In the worst-case scenario where trackdown is not able to restore the code chunks, experienced collaborators can still use Git or the information saved in the hidden .trackdown folder to manually restore all corrupted or missing parts.