Skip to content

Commit

Permalink
Add an example with tidylog to the R logging section
Browse files Browse the repository at this point in the history
Related to #4

Add an example of using `tidylog` for logging data manipulations in R to the `04-01-creating_log_files_manually.md` file.

* **New Section on `tidylog`**:
  - Add a section on using `tidylog` for logging data manipulations in R.
  - Explain how to install `tidylog`.
  - Provide an example of its usage.
  - Describe how `tidylog` logs data manipulations.
  - Reference the example paper AEJPol-2023-0640.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/larsvilhuber/self-checking-reproducibility/issues/4?shareId=XXXX-XXXX-XXXX-XXXX).
  • Loading branch information
larsvilhuber committed Dec 18, 2024
1 parent f4d5e4c commit 305d853
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 00-preliminaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@ This does not ensure
- because many intermediate files might be present that are not in the replication package
- because it does not guarantee that all the directory names are correctly adjusted everywhere in your code
- that it actually produces all the outputs
- because some outputs might be present from test runs
- because some outputs might be present from test runs
34 changes: 34 additions & 0 deletions 04-01-creating_log_files_manually.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,37 @@ See also the [Python logging documentation](https://docs.python.org/3/library/lo
::::

While some software (Stata, MATLAB) will create log files that contain commands and output, others (R, Python) will (by default) create log files that contain only output.

## Using `tidylog` for logging data manipulations in R

### Installing `tidylog`

To install the `tidylog` package, you can add it to your `requirements.txt` file in the root directory of your project. Alternatively, you can install it directly in your R script using the following command:

```R
install.packages("tidylog")
```

### Example usage of `tidylog`

Here is an example of how to use `tidylog` in the context of AEJPol-2023-0640:

```R
library(tidylog)
library(dplyr)

# Example data manipulation
data <- data %>%
filter(!is.na(variable)) %>%
mutate(new_variable = variable * 2) %>%
group_by(group_variable) %>%
summarize(mean_value = mean(new_variable, na.rm = TRUE))
```

### How `tidylog` logs data manipulations

`tidylog` automatically logs data manipulations performed using `dplyr` functions. When you use `tidylog` functions, it provides informative messages about the changes made to your data. For example, it will log the number of rows removed by a `filter` operation, the number of new columns created by a `mutate` operation, and so on. This makes it easier to track and understand the changes made to your data.

### Reference to example paper AEJPol-2023-0640

The example paper AEJPol-2023-0640 illustrates the use of `tidylog` for logging data manipulations in R. By incorporating `tidylog` into your R scripts, you can explicitly log data manipulations, making it easier to track and understand the changes made to your data.
2 changes: 1 addition & 1 deletion 04-creating_log_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ If not, ensure that they are (avoid *Stata SMCL* files, for example).

> It may be useful at this time to understand how to run code non-interactively.
>
> - [Useful resource for R](https://github.com/gastonstat/tutorial-R-noninteractive/)
> - [Useful resource for R](https://github.com/gastonstat/tutorial-R-noninteractive/)

0 comments on commit 305d853

Please sign in to comment.