@@ -10,6 +10,27 @@ get_n_warning <- function(f) {
10
10
sum(d $ token == " SYMBOL_FUNCTION_CALL" & d $ text == " warning" )
11
11
}
12
12
13
+ get_n_data.frame <- function (f ) {
14
+ d <- getParseData(parse(f , keep.source = TRUE ))
15
+ sum(d $ token == " SYMBOL_FUNCTION_CALL" & d $ text == " data.frame" )
16
+ }
17
+
18
+ test_that(" `get_n_*() detects number of calls properly" , {
19
+ withr :: local_file(" tmp.R" )
20
+ writeLines(
21
+ c(
22
+ ' stop("foo!")' ,
23
+ ' warning("bar!")' ,
24
+ " data.frame(x = 1)"
25
+ ),
26
+ " tmp.R"
27
+ )
28
+
29
+ expect_equal(get_n_stop(" tmp.R" ), 1 )
30
+ expect_equal(get_n_warning(" tmp.R" ), 1 )
31
+ expect_equal(get_n_data.frame(" tmp.R" ), 1 )
32
+ })
33
+
13
34
# Pattern is needed filter out files such as ggplot2.rdb, which is created when running covr::package_coverage()
14
35
R_files <- list.files(" ../../R" , pattern = " .*\\ .(R|r)$" , full.names = TRUE )
15
36
@@ -22,3 +43,8 @@ test_that("do not use warning()", {
22
43
warnings <- vapply(R_files , get_n_warning , integer(1 ))
23
44
expect_equal(sum(warnings ), 0 )
24
45
})
46
+
47
+ test_that(" do not use data.frame(), use `data_frame()` or `new_data_frame()`" , {
48
+ data.frames <- vapply(R_files , get_n_data.frame , integer(1 ))
49
+ expect_equal(sum(data.frames ), 0 )
50
+ })
0 commit comments