# INBO CODING CLUB 27 November 2025 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 | *** Rhea Maesele | * Hanne Van Gompel | Anne-Lie Van Praet | Larissa Bonifacio | Lawrence Whatley | Lucia Manzanares |* ## Challenge 1 ### Damiano's solution (example) Copy paste this section to show your solutions. ```r # dummy code print("This is how to insert code.") ``` ### Lawrence's solution ```r str_length(birds$metal_ring) str_starts(birds$color_ring, "C") str_ends(birds$color_ring, "R") colour_upper <- str_to_upper(birds$color_ring) identical(colour_upper, birds$color_ring) colour_upper ``` ### Larissa's solution ```r #Get the length of the metal rings str_length(birds$metal_ring) #Do the color_rings start with C? str_starts(birds$color_ring, "C", negate=FALSE) #Do the color_rings end with R? str_ends(birds$color_ring, "R", negate=FALSE) #Are all the color_rings uppercase? #solution not correct str_detect(birds$color_ring, "[:upper:]") #Set all color rings uppercase str_to_upper(birds$color_ring, locale="en") ``` ### Hanne's solution ```r # 1.1 view(str_length(birds$metal_ring)) # 1.2 view(str_starts(birds$color_ring, "C")) # 1.3 view(str_ends(birds$color_ring, "R")) # 1.4 alles veranderen naar uppercase en vergelijk originele met nieuwe --> zijn ze gelijk? all_upper_colorring <- str_to_upper(birds$color_ring) view(str_equal(birds$color_ring, all_upper_colorring)) # 1.5 view(all_upper_colorring) ``` ### Rhea's s solution ```r bird_rings <- read.delim("G:/Mijn Drive/Rhea/R/INBO R Coding Club/coding-club/data/20251127/20251127_bird_rings.tsv") # 1. Get the length of the metal rings. str_length(bird_rings$metal_ring) # 2. Do the color rings start with a "C"? str_starts(bird_rings$color_ring, "C") # 3. Do the color rings end with a "R"? str_ends(bird_rings$color_ring, "R") # 4. Are all the color rings uppercase? str_detect(bird_rings$color_ring,"[[:upper:]]") # 5. Solve all the anomalies found in (4) by setting all color rings uppercase. str_to_upper(bird_rings$color_ring) # Extra: tidyverse packages are made to work nicely together. Use stringr and dplyr to get the birds with a 6 characters long metal ring and a color ring starting with a "C" and ending with a "R". birds <- bird_rings %>% filter(str_length(bird_rings$metal_ring) == 6 & str_starts(bird_rings$color_ring, "C") & str_ends(bird_rings$color_ring, "R")) View(birds) ``` ## Challenge 2 ### Lawrence's solution ```r # 2.1 birds <- birds %>% mutate( color_ring_complete = str_c(background_color, inscription_color, "(", color_ring, ")") ) # 2.2 all(str_detect(birds$color_ring, "^[A-Za-z]+$")) all(str_sub(birds$color_ring, 3, 3) == "A") #2.3 str_detect(birds$color_ring, "[0-9]") # 2.4 birds <- birds %>% mutate( digit = str_extract(birds$color_ring, "[0-9]") ) #Extra selected_rings <- birds$color_ring[ str_detect(birds$color_ring, "^[A-Za-z]+$") & str_sub(birds$color_ring, 3, 3) == "A" ] selected_rings ``` ### Larissa's solution ```r #1. Add column color_ring_complete birds_new <- birds %>% mutate(color_ring_complete = background_color, inscription_color, "(", color_ring, ")") #2. Check if all color ring length is equal to 4 color_ring_length <- str_length(birds_new$color_ring) color_ring_length unique(color_ring_length) #answer: only 4 #3. Third letter of color_ring is always A? color_ring_A <- str_detect(birds_new$color_ring, "[:graph:][:graph:]A[:graph:]") isTRUE(color_ring_A) #answer: false #4. Is there always a digit in color_ring? color_ring_digit <- str_detect(birds_new$color_ring, "[:digit:]") isTRUE(color_ring_digit) #answer: FALSE #5. Create column digit containing first digit of color_ring, if any birds_new <- birds %>% mutate(digit = str_extract(birds_new$color_ring, "\\d")) birds_new ``` ##Lucia Manzanares birds %>% str_glue_data("{background_color}{inscription_color}({color_ring})" )->birds$color_ring_complete #2. All color rings have length 4: check it, first, if you don't believe it :-) #But are they all 4-letter only? And is the third letter always an "A"? str_count(birds$color_ring,"[:alpha:]") str_count(birds$color_ring,"[:digit:]") unique(str_locate(birds$color_ring, "A")) #3. Do the color rings contain at least a digit? str_count(birds$color_ring,"[:digit:]") #4. Create a new column called digit containing the first digit, if any, as a number. str_extract(birds$color_ring,"\\d")-> birds$digit ```r # 2.1 birds2 <- birds %>% mutate(color_ring_complete = str_glue_data(birds, "{birds$background_color}{birds$inscription_color}({birds$color_ring})", sep="")) # alternatief birds$color_ring_complete <- str_c(birds$background_color,birds$inscription_color,"(", birds$color_ring, ")", sep="") # 2.2 # all = is alles true? all(str_length(birds$color_ring) == 4) # any() = is er ten minste 1 waarde waarvoor dit waar is? # hier vraag ik: is er ten minste één color_ring met een getal aanwezig? any(str_detect(birds$color_ring, "[:digit:]")) #negate = TRUE: draait het om # is the third letter always an "A" all(str_detect(str_sub(birds$color_ring, 3), "A")) # 2.3 all(str_detect(birds$color_ring, "[:digit:]")) # some do, but not all # 2.4 birds$digit <- str_extract(birds$color_ring, "[:digit:]") ``` ## Challenge 3