Skip to content

Commit 8ddff1b

Browse files
committed
clean examples from prototype script
1 parent dc12c33 commit 8ddff1b

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

R/extract_code_as_is_prototype.R

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
code <- "
2-
# initial comment line 1
3-
# initial comment line 2
4-
a <- 1 # A comment
5-
b1 <- 2; b2 <- 2;b3 = 3 # inline comment
6-
c <- 3 # C comment
7-
# inbetween comment
8-
d <- 4
9-
# finishing comment line 1
10-
# finishing comment line 2
11-
"
12-
13-
parsed_code <- parse(text = code)
14-
comments <- extract_comments(parsed_code)
15-
pd <- utils::getParseData(parsed_code)
16-
17-
pd <- pd[pd$token != "';'", ]
18-
191
get_line_ids <- function(pd) {
202
if (pd$token[1] == "COMMENT") {
213
first_comment <- 1:(which(pd$parent == 0)[1]-1)
@@ -85,10 +67,27 @@ split_code <- function(code, lines_ids) {
8567
code_split_calls
8668
}
8769

88-
lines_ids <- get_line_ids(pd)
89-
90-
code_by_calls <- split_code(code, lines_ids)
70+
# EXAMPLE
71+
# code <- "
72+
# # initial comment line 1
73+
# # initial comment line 2
74+
# a <- 1 # A comment
75+
# b1 <- 2; b2 <- 2;b3 = 3 # inline comment
76+
# c <- 3 # C comment
77+
# # inbetween comment
78+
# d <- 4
79+
# # finishing comment line 1
80+
# # finishing comment line 2
81+
# "
82+
#
83+
# parsed_code <- parse(text = code)
84+
# comments <- extract_comments(parsed_code)
85+
# pd <- utils::getParseData(parsed_code)
86+
#
87+
# pd <- pd[pd$token != "';'", ]
88+
# lines_ids <- get_line_ids(pd)
89+
# code_by_calls <- split_code(code, lines_ids)
90+
# code_by_calls
9191

92-
code_by_calls
9392

9493

0 commit comments

Comments
 (0)