Title: | Analyze Lines of R Code the Tidy Way |
---|---|
Description: | Analyze lines of R code using tidy principles. This allows you to input lines of R code and output a data frame with one row per function included. Additionally, it facilitates code classification via included lexicons. |
Authors: | Lucy D'Agostino McGowan [aut, cre] , Jim Hester [ctb], Joshua Rosenberg [ctb], Jeff Leek [ldr] |
Maintainer: | Lucy D'Agostino McGowan <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1 |
Built: | 2024-10-27 03:04:01 UTC |
Source: | https://github.com/lucymcgowan/tidycode |
Get a tidy data frame of classifications of all functions used in your analysis
get_classifications(lexicon = NULL, include_duplicates = TRUE)
get_classifications(lexicon = NULL, include_duplicates = TRUE)
lexicon |
Character. The classification lexicon to retrieve. Either
"crowdsource" or "leeklab". If |
include_duplicates |
Logical. Indicates whether to include all functions
and classifications along with their score (default, |
A tbl_df
with columns:
func
: the function
classification
: the classification
If include_duplicates = TRUE
, will include a column:
score
: the score
If lexicon
is NULL
, will include a column:
lexicon
: the classification lexicon
# Get a data frame of all classifications get_classifications() # Get a data frame of the most prevalent classifications get_classifications(include_duplicates = FALSE) # Get a data frame of only `leeklab` classifications get_classifications("leeklab")
# Get a data frame of all classifications get_classifications() # Get a data frame of the most prevalent classifications get_classifications(include_duplicates = FALSE) # Get a data frame of only `leeklab` classifications get_classifications("leeklab")
Loads all packages called in a list of R calls and creates a data frame of all functions included in these packages. Packages that were not previously loaded that are loaded as part of this call will be detached.
get_package_functions(x)
get_package_functions(x)
x |
an R call or list of R calls |
a data frame with the following columns:
package
: The name of the package
func
: The name of the function
get_package_functions( list( quote(library(tidycode)), quote(library(purrr)) ) )
get_package_functions( list( quote(library(tidycode)), quote(library(purrr)) ) )
Get a data frame listing one function per row.
get_stopfuncs()
get_stopfuncs()
A tbl_df
with one column:
func
: the function identified as a "stopword"
get_stopfuncs()
get_stopfuncs()
Loads all R packages in the list of R calls.
load_packages(x)
load_packages(x)
x |
an R call or list of R calls |
load_packages( list( quote(library(tidycode)), quote(library(purrr)) ) )
load_packages( list( quote(library(tidycode)), quote(library(purrr)) ) )
List packages
ls_packages(x)
ls_packages(x)
x |
an R call or list of R calls |
Character. Vector of packages called.
ls_packages( list( quote(library(tidycode)), quote(library(purrr)) ) )
ls_packages( list( quote(library(tidycode)), quote(library(purrr)) ) )
Read R file(s) as a tidy data frame
read_rfiles(...)
read_rfiles(...)
... |
One or more quoted R file paths to read |
A tidy data frame, a tbl_df
, with one row per R call. There will be three columns,
file
: the path of the original R file
expr
: the R call
line
: the line of the R call
d <- read_rfiles( tidycode_example("example_plot.R"), tidycode_example("example_analysis.R") )
d <- read_rfiles( tidycode_example("example_plot.R"), tidycode_example("example_analysis.R") )
tidycode comes bundled with a few small files to use in examples. This function makes them easy to access.
tidycode_example(path = NULL)
tidycode_example(path = NULL)
path |
Name of file. If |
tidycode_example() tidycode_example("example_plot.R")
tidycode_example() tidycode_example("example_plot.R")
Unnest R calls
unnest_calls(.data, input, drop = TRUE)
unnest_calls(.data, input, drop = TRUE)
.data |
A data frame |
input |
Input column that contains an R call or list of R calls to be split into individual functions |
drop |
|
The original data frame with an additional three columns:
line
: the line number of the call
func
: the name of the function called
args
: a list of arguments
d <- read_rfiles(tidycode_example("example_plot.R")) # Unnest a model call d %>% unnest_calls(expr) # Unnest a model call and keep the call itself using the drop parameter d %>% unnest_calls(expr, drop = FALSE)
d <- read_rfiles(tidycode_example("example_plot.R")) # Unnest a model call d %>% unnest_calls(expr) # Unnest a model call and keep the call itself using the drop parameter d %>% unnest_calls(expr, drop = FALSE)