flowchart LR
D[("data/02_processed<br/>cohort.rds")] --> A["analysis/<br/>exploration (messy OK)"]
A -- "this is it!<br/>move as a function" --> S["scripts/<br/>finalized processing (functions)"]
D --> T["_targets.R<br/>pipeline"]
S --> T
T --> N["numbers<br/>numbers in the text"]
T --> F["tables and figures<br/>output/submission/"]
N --> M["manuscript/jcsm/<br/>main.qmd + section files"]
M --> W["main.docx"]
From Analysis to Manuscript in One Project
Splitting analysis / scripts / manuscript, targets, per-section manuscripts, working with co-authors, and nvim + Quarto tips
Introduction
English version — machine-assisted translation (by generative AI, Anthropic Claude) of the original Japanese hands-on. 日本語版はこちら.
When writing a paper, it often happens that the first 70% goes quickly, but the remaining 30% takes forever.
Looking back, the time went into things like:
- Building the logical structure and the background story
- Getting on top of the literature and collecting the references
- Checking the author guidelines and adjusting formatting (paragraphs, bold, figures and tables)
- Trying to write directly in English, only to end up re-translating later
- Double-checking the numbers in the tables between Excel and R
- Fixing numbers in the text, tables and figures by hand every time the analysis changes slightly
The thinking work (logical structure, the story) cannot be reduced. But much of the later-stage work can be reduced by “mechanisms”.
In this hands-on, using simulated data, we build a paper on a cross-sectional study of sarcopenia (targeting the Journal of Cachexia, Sarcopenia and Muscle (JCSM)) as a single project. Step by step, we look at a structure that takes you from analysis to the Word file for submission without ever copying a number by hand.
What you will build
In the end, you will have a project in which two commands produce the full set of submission files.
Rscript -e 'targets::tar_make()' # analysis (recomputes only what changed)
quarto render manuscript/jcsm/main.qmd --to docx # manuscript (seconds)The resulting files are:
output/manuscript/jcsm/main.docx… main text (line numbers, page numbers, Times New Roman)output/submission/Table1.docx,Table2.docx… tables (one file per table)output/submission/Fig1.tif,Fig1.eps,Fig2.tif,Fig2.eps… figures (600 dpi TIFF and EPS)


The overall flow
There is just one key point.
Only what has been moved to scripts/ goes into the paper.
Try things freely in analysis/; put decided processing in scripts/ as functions. The paper only reads the results of the functions in scripts/.
A narrated video (about 20 minutes) at the end of this page gives an overview of the whole flow.
Chapters
| Chapter | Content | Approx. time |
|---|---|---|
| 1 | Organizing the folders (analysis / reports / manuscript / scripts) | 15 min |
| 2 | Try in analysis, move to scripts (what source() is) |
25 min |
| 3 | “Recompute only what changed” with targets | 25 min |
| 4 | Split the manuscript into section files and insert numbers automatically | 30 min |
| 5 | When co-authors edit in Word (Phase A / Phase B) | 20 min |
| 6 | Keeping exploration notes, and where Python fits | 15 min |
| 7 | nvim + Quarto tips and snippets | 30 min |
| 8 | Running costs, daily routine and pre-submission checklist | 10 min |
Who this is for
- People who have done analyses in R and have used
glm()orgtsummary - People who have made documents with Quarto (or R Markdown), or would like to
- People tired of transcribing numbers into papers and double-checking them against Excel
Chapter 7 is for people analysing in nvim (LazyVim), but all other chapters work as is in RStudio or Positron.
Download the sample project
You can download the full project used in this hands-on (the data are a simulation).
jcsm_project.zip (about 120 KB)
After extracting it, run the following inside the folder to generate all files.
Rscript scripts/01_fetch/make_dummy_data.R # create the simulated data
Rscript -e 'targets::tar_make()' # analysis, tables, figures
quarto render manuscript/jcsm/main.qmd --to docx # manuscriptThe manuscript and outputs are in English, but code comments and console messages in the sample are in Japanese. Their meanings are given in the relevant chapters.
Requirements
- R 4.3 or later (4.1 or later is required for the
\(x)syntax) - Quarto 1.4 or later
- R packages:
install.packages(c(
"targets", "here", "pacman", "dplyr", "ggplot2", "gtsummary", "flextable", "officer",
"broom", "rstatix", "ggpubr", "patchwork", "ragg", "jsonlite", "arrow"
))Video
The content of this hands-on is also available as a narrated English video (about 20 minutes). Watch it first for the big picture, then check the details in this book. (A Japanese version is also available.)