Skip to content

Commit 4b86c59

Browse files
committed
Added more variables to the pdf summary
1 parent 276dfc6 commit 4b86c59

File tree

3 files changed

+46
-24
lines changed

3 files changed

+46
-24
lines changed

R/Text_utils.r

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,24 @@ format_summary_stats <- function(summary_stats) {
5050
# Merge Start_year and End_year into "Date Range"
5151
summary_stats$Date_Range <- paste(summary_stats$Start_year, summary_stats$End_year, sep = "-")
5252

53-
# Define the columns to keep
54-
columns_to_keep <- c("Date_Range",
55-
"Total_Papers",
56-
"Total_Authors",
57-
"Density",
58-
"Transitivity",
59-
"Mean_shortest_path",
60-
"Number_of_cutpoints")
61-
62-
# Filter the columns
63-
summary_stats <- summary_stats[, columns_to_keep, drop = FALSE]
64-
6553
# Give Density and Transitivity in percentage
6654
summary_stats$Density <- summary_stats$Density * 100
6755
summary_stats$Transitivity <- summary_stats$Transitivity * 100
6856

6957
# Rename columns
7058
summary_stats <- summary_stats %>%
71-
dplyr::rename(`Dates` = Date_Range,
72-
`Papers` = Total_Papers,
73-
`Authors` = Total_Authors,
74-
`Density (%)` = Density,
75-
`Transitivity (%)` = Transitivity,
76-
`Mean Shortest Path` = Mean_shortest_path,
77-
`Cutpoints` = Number_of_cutpoints)
59+
dplyr::rename_with(dplyr::recode,
60+
"Date_Range" = "Dates",
61+
"Total_Papers" = "Papers",
62+
"Total_Authors" = "Authors",
63+
"Average_Authors_per_Paper" = "Authors per Paper",
64+
"Density" = "Density (%)",
65+
"Transitivity" = "Transitivity (%)",
66+
"Mean_degree_centrality" = "Degree Centrality",
67+
"Mean_betweenness_centrality" = "Betweenness Centrality",
68+
"Mean_harmonic_centrality" = "Harmonic Centrality",
69+
"Mean_shortest_path" = "Shortest Path",
70+
"Number_of_cutpoints" = "Cutpoints")
7871

7972
return(summary_stats)
8073
}

inst/Templates/Summary_template.Rmd

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,35 @@ toc: FALSE
1111

1212
Input data: `r report_var$config$input_name`
1313

14-
```{r echo=FALSE}
15-
knitr::kable(summary_var$summary_stats, format = "latex", booktabs = TRUE, digits = 1)
14+
# General information
15+
```{r echo=FALSE, warning=FALSE}
16+
columns_to_keep <- c("Dates",
17+
"Papers",
18+
"Authors",
19+
"Authors per Paper")
20+
df <- summary_var$summary_stats[, columns_to_keep, drop = FALSE]
21+
knitr::kable(df, format = "latex", booktabs = TRUE, digits = 1)
1622
```
23+
24+
# Network properties
25+
```{r echo=FALSE, warning=FALSE}
26+
columns_to_keep <- c("Dates",
27+
"Density (%)",
28+
"Transitivity (%)",
29+
"Shortest Path",
30+
"Cutpoints")
31+
df <- summary_var$summary_stats[, columns_to_keep, drop = FALSE]
32+
knitr::kable(df, format = "latex", booktabs = TRUE, digits = 1)
33+
```
34+
35+
# Author centrality
36+
```{r echo=FALSE, warning=FALSE}
37+
columns_to_keep <- c("Dates",
38+
"Degree Centrality",
39+
"Betweenness Centrality",
40+
"Harmonic Centrality")
41+
df <- summary_var$summary_stats[, columns_to_keep, drop = FALSE]
42+
knitr::kable(df, format = "latex", booktabs = TRUE, digits = 1)
43+
```
44+
1745
More statistics in csv format can be found in `data/Summary_statistics.csv`.

tests/testthat/test-Text-utils.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ test_that("format_summary_stats works correctly", {
1717
End_year = c(2001, 2003),
1818
Total_Papers = c(10, 15),
1919
Total_Authors = c(5, 7),
20+
Average_Authors_per_Paper = c(2, 2.5),
2021
Density = c(0.5, 0.6),
2122
Transitivity = c(0.3, 0.4),
2223
Mean_shortest_path = c(2.5, 2.8),
@@ -27,15 +28,15 @@ test_that("format_summary_stats works correctly", {
2728
formatted_stats <- format_summary_stats(summary_stats)
2829

2930
# Check the structure of the formatted_stats
30-
expect_equal(ncol(formatted_stats), 7)
31-
expect_equal(colnames(formatted_stats), c("Dates", "Papers", "Authors", "Density (%)", "Transitivity (%)", "Mean Shortest Path", "Cutpoints"))
31+
expect_equal(ncol(formatted_stats), 10)
32+
expect_true(all(c("Dates", "Papers", "Authors", "Density (%)", "Transitivity (%)", "Shortest Path", "Cutpoints") %in% colnames(formatted_stats)))
3233

3334
# Check the values of the formatted_stats
3435
expect_equal(formatted_stats$Dates, c("2000-2001", "2002-2003"))
3536
expect_equal(formatted_stats$Papers, c(10, 15))
3637
expect_equal(formatted_stats$Authors, c(5, 7))
3738
expect_equal(formatted_stats$`Density (%)`, c(50, 60))
3839
expect_equal(formatted_stats$`Transitivity (%)`, c(30, 40))
39-
expect_equal(formatted_stats$`Mean Shortest Path`, c(2.5, 2.8))
40+
expect_equal(formatted_stats$`Shortest Path`, c(2.5, 2.8))
4041
expect_equal(formatted_stats$Cutpoints, c(1, 2))
4142
})

0 commit comments

Comments
 (0)