Skip to content

Instantly share code, notes, and snippets.

@tomsing1
Created February 10, 2025 17:54
Show Gist options
  • Save tomsing1/bbbaf48b7bdb4be71c144969186dfb1d to your computer and use it in GitHub Desktop.
Save tomsing1/bbbaf48b7bdb4be71c144969186dfb1d to your computer and use it in GitHub Desktop.
Example of an R script that does not follow tidyverse style guide (for a tutorial using the {lintr} and {styler} R packages
library(ggplot2);data(mtcars)
do_sampling = T
if (do_sampling==T){
if(!is.logical(do_sampling)) stop()
my_cars<- mtcars[,sample(ncol(mtcars), repl = F)]
} else
{
my_cars = mtcars
}
plotMtcars <- function(df = mtcars){
p <- ggplot(df)+ aes(x=gear, y=mpg, color = factor(cyl)) + geom_point() + theme(panel.grid = element_blank()) + labs(x = 'Gears!', y = "Mpg")
return(p)
}
if (nrow(mtcars)) {
plotMtcars(my_cars
)
}
# fit linear model
lm(mpg~factor(cyl)+gear,
data = mtcars)|>
plot(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment