Skip to content

Instantly share code, notes, and snippets.

@Rekyt
Created October 17, 2018 10:00
Show Gist options
  • Save Rekyt/a0e266711d12205c5da15154d98019e7 to your computer and use it in GitHub Desktop.
Save Rekyt/a0e266711d12205c5da15154d98019e7 to your computer and use it in GitHub Desktop.
Prettier Program for SFÉcologie 2018
---
title: "Prettier SFÉcologie 2018 Program"
author: "Matthias Grenié"
date: "17 octobre 2018"
header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage[table]{xcolor}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{threeparttablex}
- \usepackage[normalem]{ulem}
- \usepackage{makecell}
geometry: margin=1cm
documentclass: article
classoption: a4paper
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, cache = TRUE, echo = FALSE)
options(knitr.kable.NA = '')
```
```{r load_all}
# Simple scripts to output a PDF program from the SFE program
# Author: Matthias Grenié <matthias[dot]grenie[at]cefe.cnrs.fr>
# Packages ---------------------------------------------------------------------
library("tidyverse")
library("readxl")
library("knitr")
library("kableExtra")
# Download data ----------------------------------------------------------------
download.file("https://sfecologie2018.sciencesconf.org/data/pages/Program_Sfecologie2018_Excel_version_2018_10_11_.xls",
"sfe_ecology_program.xls", method = "curl")
# Load data --------------------------------------------------------------------
full_program = read_excel("sfe_ecology_program.xls") %>%
mutate(date = as.Date(date)) %>% # for dates keep only actual date
filter(!is.na(date))
complete_session = full_program %>%
# Identify session title
mutate(session = ifelse(end - start > as.difftime(25, units = "mins"),
titre, NA)) %>%
mutate(session = zoo::na.locf(session))
by_date = complete_session %>%
split(., .$date) %>%
map(~select(.x, -date))
```
```{r}
simplify_time = function(x) {
as.character(x) %>%
strftime(format = "%H:%M")
}
by_date = by_date %>%
map(~ .x %>%
mutate(start = simplify_time(start),
end = simplify_time(end),
speaker = str_extract(speaker, regex("^(.+?),")) %>%
str_remove(fixed(",")) %>%
tools::toTitleCase()) %>%
filter(titre != session |
(titre %in% c("Coffee Break", "Opening Ceremony",
"Lunch")) |
!is.na(speaker)))
```
```{r pretty_tables}
kable_functions = function(given_table, given_name) {
given_table %>%
select(start, end, salle, titre, speaker) %>%
kable("latex", longtable = TRUE, booktabs = TRUE,
caption = format(as.Date(given_name), "%A, %d %B %Y")) %>%
kable_styling(latex_options = c("striped", "repeat_header"),
full_width = TRUE) %>%
# collapse_rows(3:4, latex_hline = "none", valign = "top") %>%
column_spec(1:2, width = "2em") %>%
column_spec(3, width = "4.5em") %>%
column_spec(5, width = "8em") %>%
group_rows(index = auto_index(given_table$session),
latex_gap_space = "0.7em")
}
kable_functions(by_date$`2018-10-23`, "2018-10-23")
kable_functions(by_date$`2018-10-24`, "2018-10-24")
kable_functions(by_date$`2018-10-25`, "2018-10-25")
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment