# INBO CODING CLUB 25 February 2021 Welcome! ## Share your code snippet If you want to share your code snippet, copy paste your snippet within a section of three backticks (```): As an **example**: ``` library(tidyverse) ``` (*you can copy paste this example and add your code further down*) ## Yellow sticky notes No yellow sticky notes online. Put your name + " | " and add a "*" each time you solve a challenge (see below). ## Participants Name | Challenges --- | --- Damiano Oldoni | Dirk Maes | ** Lynn Pallemaerts | ** An Leyssen | Amber Mertens | Hans Van Calster | *** Adriaan Seynaeve | Luc De Bruyn |* Anja Leyman | ## Challenge 1 Hans: ``` #' read a set of research grade observations from text file #' `20210125_occurrence_iNaturalist_researchgrade_obs.txt` inat <- read_tsv(file = "./data/20210225/20210125_occurrence_iNaturalist_researchgrade_obs.txt") #' read data file `20210225_gent_groeiperwijk.csv` containing the demographic evolution of Ghent districts from 1999 to 2009 # of here() gebruiken om path te definiëren (install.packages("here")) gent <- read_csv2(here::here("data", "20210225", "20210225_gent_groeiperwijk.csv"), quote = "'") #' read sheet `ALL DATA` from Excel datafile `20210225_manta_2014_2015.xlsx` with #' manta related data. #' manta <- read_excel("data/20200121/20200121_manta_master_database_2014_2015.xlsx", sheet = "ALL DATA", skip = 1) #' Read butterfly related data file `20210225_butterflies_counts.txt` with #' semicolon (;) as delimiter, dot (.) as decimal mark and question mark (?) as #' NA. Read only the first 500 rows. Be sure column `Date` is parsed as #' datetime by using `format = "%d/%m/%Y %H:%M:%S"`. butterfly <- read_delim("data/20210225/20210225_butterflies_counts.txt", delim = ";", locale = locale(decimal_mark = "."), na = "?", n_max = 500, col_types = cols(Date = col_datetime(format = "%d/%m/%Y %H:%M:%S"))) #' How to examine the column specifications for the dataframes you have just read? spec(butterfly) spec(gent) purrr::map(manta,class) ``` ## Challenge 2 Lynn ``` hyacint <- read_sheet("https://docs.google.com/spreadsheets/d/1Tc8U-ud4dEcxgOojS80w7gdQQ-Ac85A4dN-u47NSmYg", sheet='HyaHoVrBl', na=c("NA","na","NaN")) sheets_get("https://docs.google.com/spreadsheets/d/1Tc8U-ud4dEcxgOojS80w7gdQQ-Ac85A4dN-u47NSmYg") hyacint_cov_link <- "https://docs.google.com/spreadsheets/d/e/2PACX-1vRFAWYrZmgBRPXQnw3Io5T_29ZrGkH-Ds4yulFd02MIPcalGPtzyQ3cujgAdwzfnRNYIWQFf1oKjgM3/pub?gid=1007047746&single=true&output=csv" hyacint_offline <- read_csv(file = hyacint_cov_link, na=c("NA","na")) ``` Hans: ``` #' 1. Read the sheet `HyaHoVrBl` from a googlesheet about [hyacint coverage in Ename](https://docs.google.com/spreadsheets/d/1Tc8U-ud4dEcxgOojS80w7gdQQ-Ac85A4dN-u47NSmYg)(https://docs.google.com/spreadsheets/d/1Tc8U-ud4dEcxgOojS80w7gdQQ-Ac85A4dN-u47NSmYg) paying attention to import all columns correctly hyacinth <- read_sheet(ss= "1Tc8U-ud4dEcxgOojS80w7gdQQ-Ac85A4dN-u47NSmYg", sheet = "HyaHoVrBl", na = c('na', 'NA', 'NaN')) hyacinth #get rid of spaces in column names library(janitor) hyacinth <- hyacinth %>% clean_names() #' 2. Get metadata of the googlesheet in 1 gs4_get(ss = "1Tc8U-ud4dEcxgOojS80w7gdQQ-Ac85A4dN-u47NSmYg") #' 3. But what if you don't want to allow tidyverse API to get access to your INBO #' Google account? Well, you can publish the sheet to the web as csv and then #' import it via `read_delim()` or `read_csv()`. Note: This method is useful if you #' don't have to import a lot of Googlesheets and they can be publicly available. #' Read the csv generated in this way by using this link: #' hyacint_cov_link <- "https://docs.google.com/spreadsheets/d/e/2PACX-1vRFAWYrZmgBRPXQnw3Io5T_29ZrGkH-Ds4yulFd02MIPcalGPtzyQ3cujgAdwzfnRNYIWQFf1oKjgM3/pub?gid=1007047746&single=true&output=csv" hyacinth_from_csv <- read_csv(hyacint_cov_link, na = c('NA', 'na', 'NaN')) %>% clean_names() ``` ## INTERMEZZO ## Challenge 3 Hans: ``` days_walloon <- c("londi", "mårdi", "mierkidi", "djudi", "vénrdi", "semdi", "dimegne") months_walloon <- c("djanvî","fevrî", "måss", "avri", "may", "djun", "djulete", "awousse","setimbre", "octôbe", "nôvimbe", "decimbe") days_abbr_walloon <- c("lon", "mår", "mie", "dju", "vén", "sem", "dim") months_abbr_walloon <- c("djan","fev", "mås", "avr", "may", "djun", "djul", "awou","set", "oct", "nôv", "dec") walloon <- read_csv(file = "data/20210225/20210225_rainfall_waterloo.csv", skip = 6, locale = locale(grouping_mark = "'", date_names = date_names( mon = months_walloon, mon_ab = months_abbr_walloon, day = days_walloon, day_ab = days_abbr_walloon ), date_format = "%a %d %B %Y"), col_types = cols(`AV Quality Code` = col_number(), Hour = col_number()) ) walloon ``` ## Bonus challenge