Skip to content

Instantly share code, notes, and snippets.

@jenrichmond
Created October 6, 2022 04:54
Show Gist options
  • Save jenrichmond/43b83005969ad27c3a2b3acd3078cb44 to your computer and use it in GitHub Desktop.
Save jenrichmond/43b83005969ad27c3a2b3acd3078cb44 to your computer and use it in GitHub Desktop.
use knitr::spin to convert script to markdown
#' this script demos how to use knitr::spin to turn a .R script into a knitted markdown
#' these funny hash/tick comments will be read in the .md doc as text
#' everything else will be run as a code chunk
#' to use spin, in the console run knitr::spin(file = spintest.R)
#' you will end up with a .md doc in your files, open it and knit to html
#' load packages
library(tidyverse)
library(palmerpenguins)
#' print p values not in scientific notation
options(scipen = 99)
#' filter penguin data to include just adelie and gentoo
ag <- penguins %>%
filter(species %in% c("Adelie", "Gentoo"))
# boxplot body mass by species
ag %>%
ggplot(aes(x = species, y = body_mass_g)) +
geom_boxplot()
#' t-test body mass by species
t.test(body_mass_g ~ species, data = ag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment