Skip to content

Commit

Permalink
create code2list in teal.daata
Browse files Browse the repository at this point in the history
  • Loading branch information
m7pr committed Nov 6, 2024
1 parent 84f8ceb commit b465322
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 25 additions & 0 deletions R/teal_data-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,28 @@ new_teal_data <- function(data,
verified = verified
)
}


#' Reshape code to the list
#'
#' List will be divided by the calls. Each element of the list contains `id` and `dependency` attributes.
#'
#' @param code `character` with the code.
#'
#' @return list of `character`s of the length equal to the number of calls in `code`.
#'
#' @keywords internal
#' @noRd
code2list <- function(code) {
checkmate::assert_character(code, null.ok = TRUE)
if (length(code)) {
lapply(split_code(code), function(current_code) {
attr(current_code, "id") <- sample.int(.Machine$integer.max, 1)
parsed_code <- parse(text = trimws(current_code), keep.source = TRUE)
attr(current_code, "dependency") <- extract_dependency(parsed_code)
current_code
})
} else {
list(character(0))
}
}
3 changes: 2 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# use non-exported function from teal.code
lang2calls <- getFromNamespace("lang2calls", "teal.code")
code2list <- getFromNamespace("code2list", "teal.code")
extract_dependency <- getFromNamespace("extract_dependency", "teal.code")
split_code <- getFromNamespace("split_code", "teal.code")

0 comments on commit b465322

Please sign in to comment.