From 2214bcd842b320e097dac370b4fdf6f2ea652304 Mon Sep 17 00:00:00 2001 From: Shannon Pileggi Date: Sun, 10 Sep 2023 18:39:44 -0400 Subject: [PATCH] solutions --- R/01_write-installed-packages.R | 4 ++++ R/02_wrangle-packages.R | 10 ++++++++++ R/03_barchart-packages-built.R | 10 ++++++++++ README.md | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/R/01_write-installed-packages.R b/R/01_write-installed-packages.R index 2e40a2c..f924a95 100644 --- a/R/01_write-installed-packages.R +++ b/R/01_write-installed-packages.R @@ -2,6 +2,9 @@ # 1. Create a data frame of your installed packages. --------------------------- # hint: installed.packages() is the function you need +library(tidyverse) +df_pkgs <- installed.packages() |> + as_tibble() # optional: select just some of the variables, such as # * Package @@ -13,6 +16,7 @@ # 2. Write this data frame to data/installed-packages.csv. --------------------- # hint: readr::write_csv() or write.table() # idea: try using here::here() to create the file path +readr::write_csv(df_pkgs, "data/installed-packages.csv") # YES overwrite the file that is there now (or delete it first) # that is an old result from Jenny diff --git a/R/02_wrangle-packages.R b/R/02_wrangle-packages.R index 561d8cf..5d3beca 100644 --- a/R/02_wrangle-packages.R +++ b/R/02_wrangle-packages.R @@ -3,6 +3,8 @@ # 1. Create a data frame by reading from data/installed-packages.csv. ---------- # hint: readr::read_csv() or read.csv() # idea: try using here::here() to create the file path +library(tidyverse) +df_pkgs <- readr::read_csv(here::here("data", "installed-packages.csv")) # 2. Filter out the base and recommended packages. ----------------------------- @@ -16,6 +18,10 @@ df_pkgs_addon <- df_pkgs |> # 3. Write this new, smaller data frame to data/add-on-packages.csv. ----------- # hint: readr::write_csv() or write.table() # idea: try using here::here() to create the file path +readr::write_csv( + df_pkgs_addon, + here::here("data", "add-on-packages.csv") +) # 4. Summarize the packages with a frequency table of the version in Built. ---- # if you use dplyr, code like this will work: @@ -30,3 +36,7 @@ pkgs_addon_freqtable <- df_pkgs_addon |> # YES overwrite the files that are there now # they are old output from Jenny # they are just examples +readr::write_csv( + pkgs_addon_freqtable, + here::here("data", "add-on-packages-freqtable.csv") +) diff --git a/R/03_barchart-packages-built.R b/R/03_barchart-packages-built.R index d990b59..43c1ee0 100644 --- a/R/03_barchart-packages-built.R +++ b/R/03_barchart-packages-built.R @@ -3,6 +3,10 @@ # 1. Read data/add-on-packages-freqtable.csv into a data frame.----------------- # hint: readr::read_csv() or read.csv() # idea: try using here::here() to create the file path +library(tidyverse) +pkgs_addon_freqtable <- readr::read_csv( + here::here("data", "pkgs_addon_freqtable.csv") +) # 2. Make a barchart from the frequency table you read in. --------------------- # if you use ggplot2, code like this will work: @@ -15,3 +19,9 @@ ggplot(pkgs_addon_freqtable, aes(x = Built, y = n)) + # ---- # YES overwrite the file that is there now # that is old output from Jenny +ggsave( + here::here( + "figs", + "built-barchart.png" + ) +) diff --git a/README.md b/README.md index a0d5beb..6a4ade0 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,6 @@ usethis::use_course("rstats-wtf/wtf-packages-report") - `R/02_wrangle-packages.R` - `R/03_barchart-packages-built.R` * It's OK if you don't finish! We can keep working on this later. -* If you finish quickly, write an R script to run the whole analysis and, perhaps, another script that does a `make clean` style reset. +* If you finish quickly, write an R script to run the whole analysis. Solutions are in the [solutions](https://github.com/rstats-wtf/wtf-packages-report/commit/f9fe5aacc004cf8c79356acdd4638f641f6f8ae7) branch.