Skip to content

Finding symbols #80

@llrs-roche

Description

@llrs-roche

Hi,

Thanks for the README it was very informative to get started and run it locally on a package. It was faster than expected (on a package with almost no tests).

I'm using covtracer to find which code can't be reached out with shiny::testServer. For that I need to find which function is a server and which is not.
I noticed that ttdf delivers some rows with alias but no source code. This is because those alias have no source code (the alias of the name of the package and similar code objects).

Also It would be great if besides the alias there could be a function to extract the names of the symbols and the lines of code. The following code is after running the README.

Some code for finding alias without source code

s <- ttdf[["srcref"]]
functions_names <- names(ttdf$srcref)
nas <- which(is.na(functions_names))
functions_names <- functions_names[-nas]
u_alias <- ttdf$alias |> unique()
ufn <- functions_names |> unique()
setdiff(u_alias, ufn)

Code to extract name and line for each symbol with source code

For all:

src <- ttdf[["srcref"]]
functions_names <- names(ttdf$srcref)
nas <- which(is.na(functions_names))
functions_names <- functions_names[-nas]
src_text <- lapply(src[-nas], as.character, useSource = FALSE)
srcrefs <- unlist(src_text, use.names = TRUE)
lines <- strcapture(pattern = "([[:digit:]]+):([[:digit:]]+) to ([[:digit:]]+):([[:digit:]]+)>", 
                    srcrefs,
                    proto = data.frame(
                      start_line = integer(),
                      start_col = integer(),
                      end_line = integer(),
                      end_col = integer()
                    ))
data_f <- cbind(functions = functions_names, lines) |> 
  unique()

Faster more direct (but might miss some other cases)

covv <- as.data.frame(cov)
covv_s <- covv |> dplyr::summarise(.by =functions, first_line = min(first_line), last_line=max(last_line))
covv_s

Sorry for the messy code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions