Type: Package
Title: Analyze Lines of R Code the Tidy Way
Version: 0.1.1
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.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
Imports: purrr, pryr, tibble, rlang, glue, matahari
Suggests: testthat, covr, knitr, rmarkdown, dplyr
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2019年12月10日 15:35:41 UTC; lucymcgowan
Author: Lucy D'Agostino McGowan ORCID iD [aut, cre], Jim Hester [ctb], Jeff Leek [ldr]
Maintainer: Lucy D'Agostino McGowan <lucydagostino@gmail.com>
Repository: CRAN
Date/Publication: 2019年12月10日 19:30:02 UTC

Pipe operator

Description

Pipe operator

Usage

lhs %>% rhs

Get a tidy data frame of classifications of all functions used in your analysis

Description

Get a tidy data frame of classifications of all functions used in your analysis

Usage

get_classifications(lexicon = NULL, include_duplicates = TRUE)

Arguments

lexicon

Character. The classification lexicon to retrieve. Either "crowdsource" or "leeklab". If NULL (default), will return all lexicons.

include_duplicates

Logical. Indicates whether to include all functions and classifications along with their score (default, TRUE) - this may result in multiple lines (with multiple classifications) for a single function. If FALSE, the most prevalent classification will be selected.

Value

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

Examples

# 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 tidy data frame of a "stopword" lexicon for R functions

Description

Get a data frame listing one function per row.

Usage

get_stopfuncs()

Value

A tbl_df with one column:

  • func: the function identified as a "stopword"

Examples

get_stopfuncs()

List packages

Description

List packages

Usage

ls_packages(x)

Arguments

x

an R call or list of R calls

Value

Character. Vector of packages called.

Examples

ls_packages(
 list(
 quote(library(tidycode)),
 quote(library(purrr)))
 )

Read R file(s) as a tidy data frame

Description

Read R file(s) as a tidy data frame

Usage

read_rfiles(...)

Arguments

...

One or more quoted R file paths to read

Value

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

Examples

d <- read_rfiles(
 tidycode_example("example_plot.R"),
 tidycode_example("example_analysis.R")
)

Get path to example file

Description

tidycode comes bundled with a few small files to use in examples. This function makes them easy to access.

Usage

tidycode_example(path = NULL)

Arguments

path

Name of file. If NULL, the example files will be listed.

Examples

tidycode_example()
tidycode_example("example_plot.R")

Unnest R calls

Description

Unnest R calls

Usage

unnest_calls(.data, input, drop = TRUE)

Arguments

.data

A data frame

input

Input column that contains an R call or list of R calls to be split into individual functions

drop

logical. Whether the original input column should be dropped.

Value

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

Examples

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)

AltStyle によって変換されたページ (->オリジナル) /