Created
October 13, 2022 14:01
-
-
Save graebnerc/642cacdb29f1cf98057921ae5f4a8cd5 to your computer and use it in GitHub Desktop.
Scripts containing the code developed during the 7th lectore on project management and data import, as well as solutions to the exercises
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
Scripts containing the code developed during the 7th lectore on project management and data import, as well as solutions to the exercises |
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
here::i_am("R/the_here_script.R") | |
# Script assumes the following directory structure: | |
# R/import_data.R | |
# data/raw/fread_expls-1.csv | |
# It also includes the solution to the final exercise below | |
here::i_am("R/import_data.R") | |
library(here) | |
library(data.table) | |
library(tibble) | |
data_path <- here("data/raw/fread_expls-1.csv") | |
expl_data_1 <- fread(file = data_path) | |
expl_data_1 <- tibble::as_tibble(expl_data_1) # Not strictly necessary but useful | |
expl_data_1 | |
data_path_2 <- here("data/raw/fread_expls-2.csv") | |
expl_data_2 <- fread(file = data_path_2) # Default values do not work... | |
expl_data_2 # ... as you can see here | |
expl_data_2 <- fread(file = data_path_2, sep = "'", dec = ":") | |
expl_data_2 <- tibble::as_tibble(expl_data_2) | |
expl_data_2 | |
data_path_3 <- here("data/raw/fread_expls-3.csv") | |
expl_data_3 <- fread(file = data_path_3) | |
expl_data_3 <- tibble::as_tibble(expl_data_3) | |
head(expl_data_3) # column commoditycode is missing leading zero! | |
expl_data_3 <- fread( | |
file = data_path_3, | |
colClasses = c(rep("character", 2), rep("double", 2)) | |
) | |
# Alternative only referring one column to change: | |
expl_data_3 <- fread( | |
file = data_path_3, | |
colClasses = c("commoditycode"="character", "cgroup"="factor") | |
) | |
expl_data_3 <- tibble::as_tibble(expl_data_3) | |
head(expl_data_3) | |
str(expl_data_3) |
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
here::i_am("R/the_here_script.R") | |
library(ggplot2) | |
test_plot <- ggplot() + theme_dark() + labs(title = "An empty plot") | |
test_plot | |
plot_name <- here::here("output/dark_plot.pdf") | |
plot_name_jpg <- here::here("output/dark_plot.jpg") | |
plot_name_png <- here::here("output/dark_plot.png") | |
ggsave(filename = plot_name, plot = test_plot, width = 6, height = 3) | |
ggsave(filename = plot_name_jpg) | |
ggsave(filename = plot_name_png) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment