class: center, middle, inverse, title-slide # Get data from ClimMob to R ### KauĂȘ de Sousa ### 2021 --- # Content * API key * Project data * Trial data # Lecture This lecture is available on [Youtube](https://www.youtube.com/playlist?list=PLpT37wNlyZlS2QL67Qn-eLI8oETBr5sKm) --- # Set up For this lecture we need to package ClimMobTools. We install it from CRAN. ```r install.packages("ClimMobTools") ``` Then we load the packages with `library()`. We run this command every time we open a new R section ```r library("ClimMobTools") ``` --- class: middle, inverse # API key --- # API key Log-in into your ClimMob account at https://climmob.net/climmob3/login <center> <img src="img/log-in.png" width="80%"/> </center> --- # API key Click on "Actions" and then "Profile" <center> <img src="img/api-key1.png" width="80%"/> </center> --- # API key The API key is on the bottom of your profile information <center> <img src="img/api-key2.png" width="80%"/> </center> --- class: middle, inverse # Project data --- # Project data To access the information about your tricot projects we use the function `getProjectsCM()` from ClimMobTools, the main input is your API key ```r key <- "d39a3c66-5822-4930-a9d4-50e7da041e77" projects <- getProjectsCM(key) projects[8:10, ] ``` ``` ## project_id name status creation_date ## <chr> <chr> <chr> <date> ## 8: test Registry-only concluded 2019-11-08 ## 9: chocolatesnepal Chocolates Nepal concluded 2019-10-27 ## 10: flowers Flowers wageningen concluded 2019-04-17 ## intended_participants registration_progress last_registration_activity ## <int> <dbl> <chr> ## 8: 30 13.33 1 year ago ## 9: 26 84.62 1 year ago ## 10: 7 100.00 1 year ago ``` --- # Project data If you are a client from an alternative ClimMob server, you may need the argument "server" ```r key <- "your-key" servername <- "server-name" projects <- getProjectsCM(key, server = servername) ``` --- class: middle, inverse # Trial data --- # Trial data The trial data is retrieved with the function `getDataCM()`. We need the API key and the project id. Lets retrieve the data from the project "breadwheat" This returns the data frame in a "tidy" format. ```r dt <- getDataCM(key, project = "breadwheat") dt[1:6, ] ``` ``` ## id moment variable value ## <int> <fct> <chr> <chr> ## 1: 1 package participant_name Participant Name1 ## 2: 1 package item_A CSW18 ## 3: 1 package item_B PBW502 ## 4: 1 package item_C HW2045 ## 5: 1 package project_name breadwheat ## 6: 1 registration surveyid 14c7cfd6-51c3-11e9-a394-0686a00ebfc0 ``` .footnote[ [1] [Read more about tidy data](https://cran.r-project.org/web/packages/tidyr/vignettes/tidy-data.html) ] --- # Trial data To return the data in the wider format, we use the argument `pivot.wider = TRUE` ```r dt <- getDataCM(key, project = "breadwheat", pivot.wider = TRUE) dt[1:6, 1:5] ``` ``` ## id package_participant_name package_item_A package_item_B package_item_C ## <chr> <chr> <chr> <chr> <chr> ## 1: 1 Participant Name1 CSW18 PBW502 HW2045 ## 2: 2 Participant Name2 WR544 HD2985 PBW550 ## 3: 3 Participant Name3 PBW343 HD2932 RAJ4120 ## 4: 4 Participant Name4 HP1633 DBW17 CSW18 ## 5: 5 Participant Name5 CSW18 DBW17 HD2932 ## 6: 6 Participant Name6 HP1633 HW2045 CSW18 ``` --- # **Thank you!** .pull-left[ <img src="img/logos-v.png" width="50%"/> ] .pull-right[ <img src="https://img.icons8.com/color/64/000000/twitter.png" width = "10%">[@desousakaue](https://twitter.com/desousakaue) <img src="https://img.icons8.com/ios-filled/50/000000/email-open.png" width = "10%">[k.desousa@cgiar.org](mailto:k.desousa@cgiar.org) <br><br><br><br><br><br><br><br><br><br> [Back to the main page](index.html) ]