Commit 0742b89c authored by amarell's avatar amarell

Exercise 02 (4th part): create csv data file and analysis

parent 998f4228
......@@ -5,7 +5,8 @@ This is Anders' logbook for the MOOC on reproducible science
Authors: Anders Mårell
Created: 2023--06-09
## First day - 2023-06-08 <!--MOOC Reproducible science -->
## 2023-06-08 <!--MOOC Reproducible science-->
First day
Module 1 and parts of module 2. Access to the gitlab was not working so not possible to do some of the exercises.
- Learnt about some generalities about making reproducible science and its history.
......@@ -15,5 +16,6 @@ Module 1 and parts of module 2. Access to the gitlab was not working so not poss
- administrators for efno: Anders Mårell and Frédéric Gosselin
- added subgroups (efno-st, MOOC-IGN) and members
## Second day - 2023-06-09 <!--MOOC Reproducible science-->
## 2023-06-09 <!--MOOC Reproducible science-->
Second day
Continued with module 2 and the exercises in module 1 and module 2.
---
title: "Your title"
author: "Your name"
date: "Today's date"
title: "Analyzing my logbook data"
author: "Anders Mårell"
date: "2023-06-09"
output: html_document
editor_options:
chunk_output_type: console
---
......@@ -10,24 +12,51 @@ output: html_document
knitr::opts_chunk$set(echo = TRUE)
```
## Some explanations
This is an R Markdown document that you can easily export to HTML, PDF, and MS Word formats. For more information on R Markdown, see <http://rmarkdown.rstudio.com>.
# Tags used per day
Read in the journal file *Readme.md* that is in the *journal* folder. Then extract the lines with date headings at the second level. We can then extract the tags and the dates:
```{r}
# Import data ------------------------------------------------------------------
MyData <- readLines(con = here::here("journal", "Readme.md"))
# Extract lines with headings at the 2nd level ---------------------------------
MyDates <- MyData[grepl(pattern = "##", x = MyData)]
# Extract the tags -------------------------------------------------------------
MyTags <-
sub(pattern = "-->",
replacement = "",
x = sub(pattern = ".*<!--",
replacement = "",
x = MyDates))
# Extract the dates and replace string by dates --------------------------------
MyDates <-
substring(
MyDates,
regexpr(pattern = "[0-9]{4}-[0-9]{2}-[0-9]{2}", text = MyDates),
regexpr(pattern = "[0-9]{4}-[0-9]{2}-[0-9]{2}", text = MyDates) + 9)
# Format as date ---------------------------------------------------------------
MyDates <- as.Date(MyDates)
```
When you click on the button **Knit**, the document will be compiled in order to re-execute the R code and to include the results into the final document. As we have shown in the video, R code is inserted as follows:
We can now create a data frame with the date and tags:
```{r cars}
summary(cars)
```{r}
MyTags <- data.frame(date = MyDates, tags = MyTags)
```
It is also straightforward to include figures. For example:
Save the data frame as a csv file in the *module2/exo4* folder:
```{r pressure, echo=FALSE}
plot(pressure)
```{r}
write.table(x = MyTags,
file = here::here("module2", "exo4", "mytags.csv"),
row.names = FALSE, col.names = TRUE,
fileEncoding = "UTF-8", quote = FALSE, sep = ";")
```
Note the parameter `echo = FALSE` that indicates that the code will not appear in the final version of the document. We recommend not to use this parameter in the context of this MOOC, because we want your data analyses to be perfectly transparent and reproducible.
Since the results are not stored in Rmd files, you should generate an HTML or PDF version of your exercises and commit them. Otherwise reading and checking your analysis will be difficult for anyone else but you.
Calculate the number of days per tag:
```{r}
table(MyTags$tags)
```
Now it's your turn! You can delete all this information and replace it by your computational document.
date;tags
2023-06-08;MOOC Reproducible science
2023-06-09;MOOC Reproducible science
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment