Created
February 10, 2025 17:54
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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