Skip to content

Commit 8817ada

Browse files
committed
initial format with Air
1 parent 670c7c0 commit 8817ada

6 files changed

Lines changed: 55 additions & 86 deletions

File tree

R/get_parsed_tibble.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ file_validation = function(filename) {
3636
#' example_script("generic_script") |>
3737
#' get_parsed_tibble()
3838
get_parsed_tibble = function(filename, file_validation = TRUE) {
39-
if (file_validation) file_validation(filename = filename)
39+
if (file_validation) {
40+
file_validation(filename = filename)
41+
}
4042
parsed_file = filename |>
4143
base::parse(file = _, keep.source = TRUE) |>
4244
utils::getParseData(x = _) |>

inst/examples/generic_script.R

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,23 @@ dplyr::select(cars, speed)
55

66
# special function for
77
for (i in c(1, 2)) {
8-
# special function +
8+
# special function +
99
2 + 2
1010
}
1111

1212
base::c(1, 2)
1313

14-
while (FALSE) {2 + 2}
14+
while (FALSE) {
15+
2 + 2
16+
}
1517

1618
library(dplyr)
1719
require(ggplot2)
1820

1921
library(ggplot2)
2022

21-
test_func = function(x){
22-
return(x + 2)
23+
test_func = function(x) {
24+
return(x + 2)
2325
}
2426

2527
test_func(3)
26-
27-
28-
29-
30-
31-

inst/examples/generic_script2.R

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@ dplyr::select(cars, speed)
55

66
# special function for
77
for (i in c(1, 2)) {
8-
# special function +
8+
# special function +
99
2 + 2
1010
}
1111

12-
while (FALSE) {2 + 2}
12+
while (FALSE) {
13+
2 + 2
14+
}
1315

1416
library(dplyr)
1517
require(ggplot2)
1618

1719
library(ggplot2)
18-
19-
20-
21-
22-
23-

inst/examples/generic_script_A.R

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@ dplyr::select(cars, speed)
55

66
# special function for
77
for (i in c(1, 2)) {
8-
# special function +
8+
# special function +
99
2 + 2
1010
}
1111

1212
base::c(1, 2)
1313

14-
while (FALSE) {2 + 2}
14+
while (FALSE) {
15+
2 + 2
16+
}
1517

1618
library(dplyr)
1719
require(ggplot2)
1820

1921
library(ggplot2)
2022

21-
test_func = function(x){
22-
return(x + 2)
23+
test_func = function(x) {
24+
return(x + 2)
2325
}
2426

2527
test_func(3)
@@ -42,9 +44,3 @@ bad_pipe = mtcars %>%
4244

4345
good_pipe = mtcars |>
4446
filter(mpg > 20)
45-
46-
47-
48-
49-
50-

inst/examples/generic_script_gt.R

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ library(stringr)
1212
library(cowplot)
1313
library(GGally)
1414

15-
my_sim = function(parm1, parm2){
15+
my_sim = function(parm1, parm2) {
1616
my_obs = rnorm(n = 10000, mean = parm1, sd = parm2)
1717
return(mean(my_obs))
1818
}
@@ -27,26 +27,22 @@ sim_data1 = expand.grid(mu = settingsA, sigma = settingsB)
2727
set.seed(123)
2828
for (i in seq_len(length.out = nrow(sim_data1))) {
2929
sim_data1$observedmean[i] = my_sim(
30-
parm1 = sim_data1$mu[i],
30+
parm1 = sim_data1$mu[i],
3131
parm2 = sim_data1$sigma[i]
3232
)
3333
}
3434

3535
# But we should use dplyr
3636
set.seed(123)
37-
sim_data2 = sim_data1 |>
37+
sim_data2 = sim_data1 |>
3838
rowwise() |>
3939
mutate(observedmean = my_sim(parm1 = mu, parm2 = sigma))
4040

41-
sim_data1 |>
42-
pivot_wider(names_from = mu, values_from = observedmean) |>
43-
gt::gt() |>
41+
sim_data1 |>
42+
pivot_wider(names_from = mu, values_from = observedmean) |>
43+
gt::gt() |>
4444
gt::tab_options(latex.use_longtable = TRUE)
45-
sim_data2 |>
46-
pivot_wider(names_from = mu, values_from = observedmean) |>
47-
gt::gt() |>
45+
sim_data2 |>
46+
pivot_wider(names_from = mu, values_from = observedmean) |>
47+
gt::gt() |>
4848
gt::tab_options(latex.use_longtable = TRUE)
49-
50-
51-
52-
Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,34 @@
1-
test_that(
2-
desc = "Validating file exists.",
3-
code = {
4-
expect_no_error(
5-
object = file_validation(
6-
filename = example_script("generic_script")
7-
)
1+
test_that(desc = "Validating file exists.", code = {
2+
expect_no_error(
3+
object = file_validation(
4+
filename = example_script("generic_script")
85
)
9-
}
10-
)
6+
)
7+
})
118

12-
test_that(
13-
desc = "Ensuring error message exists.",
14-
code = {
15-
expect_error(
16-
object = file_validation(
17-
filename = "this_file_does_not_exist.R"
18-
)
9+
test_that(desc = "Ensuring error message exists.", code = {
10+
expect_error(
11+
object = file_validation(
12+
filename = "this_file_does_not_exist.R"
1913
)
20-
}
21-
)
22-
23-
test_that(
24-
desc = "Verifying warning.",
25-
code = {
26-
expect_warning(
27-
object = file_validation(
28-
filename = paste0(
29-
system.file(package = "autogradeR"),
30-
"/../DESCRIPTION"
31-
)
14+
)
15+
})
16+
17+
test_that(desc = "Verifying warning.", code = {
18+
expect_warning(
19+
object = file_validation(
20+
filename = paste0(
21+
system.file(package = "autogradeR"),
22+
"/../DESCRIPTION"
3223
)
3324
)
34-
}
35-
)
25+
)
26+
})
3627

37-
test_that(
38-
desc = "Able to parse a script.",
39-
code = {
40-
expect_snapshot(
41-
x = get_parsed_tibble(
42-
filename = example_script("generic_script")
43-
)
28+
test_that(desc = "Able to parse a script.", code = {
29+
expect_snapshot(
30+
x = get_parsed_tibble(
31+
filename = example_script("generic_script")
4432
)
45-
}
46-
)
47-
48-
49-
50-
51-
33+
)
34+
})

0 commit comments

Comments
 (0)