diff --git a/API b/API index 98900f5f0..cab8f302a 100644 --- a/API +++ b/API @@ -4,6 +4,7 @@ create_style_guide(initialize = default_style_guide_attributes, line_break = NULL, space = NULL, token = NULL, indention = NULL, use_raw_indention = FALSE, reindention = tidyverse_reindention()) default_style_guide_attributes(pd_flat) +equals_style() specify_math_token_spacing(zero = "'^'", one = c("'+'", "'-'", "'*'", "'/'")) specify_reindention(regex_pattern = NULL, indention = 0, comments_only = TRUE) style_dir(path = ".", ..., style = tidyverse_style, transformers = style(...), filetype = "R", recursive = TRUE, exclude_files = NULL, include_roxygen_examples = TRUE) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f695de09f..91ad6ec67 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -178,3 +178,16 @@ indicates for every row in a parse table whether it contains an `else` token. The use of closures is discouraged. We prefer to prefill a template function with `purrr::partial()`. + +## Testing + +We have a testing framework powered by `test_collection()`. +Essentially, there is an \*-in.R file and a \*-out.R file. The \*-in.R file is the +input that is transformed and - if it matches the *-out.R file, the test has +passed. You can create an \*-in.R file, run `devtools::test(f = "[your file]")` +and an \*-out.R file is generated. If the file matches your expectation, +you can commit it. Note that files are overwritten and version control should be +used to track failed tests. +The files are placed in `tests/testthat` under the category they fit. +Please have a look at the documentation for `test_collection()` and see other +unit tests. Let me know if there is anything unclear about this. diff --git a/DESCRIPTION b/DESCRIPTION index 172229f3f..fc76b250d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,34 +11,34 @@ Authors@R: family = "Walthert", role = c("cre", "aut"), email = "lorenz.walthert@icloud.com")) -Description: Pretty-prints R code without changing the - user's formatting intent. +Description: Pretty-prints R code without changing the user's + formatting intent. License: GPL-3 URL: https://github.com/r-lib/styler BugReports: https://github.com/r-lib/styler/issues Imports: - backports, + backports (>= 1.1.0), cli, - magrittr, + fs, + magrittr (>= 1.0.1), purrr (>= 0.2.3), rematch2, rlang (>= 0.1.1), - rprojroot, + rprojroot (>= 1.1), tibble (>= 1.4.2), tools, withr, xfun Suggests: - data.tree, + data.tree (>= 0.1.6), dplyr, here, knitr, prettycode, rmarkdown, - rstudioapi, + rstudioapi (>= 0.7), testthat -VignetteBuilder: - knitr +VignetteBuilder: knitr Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace", diff --git a/NAMESPACE b/NAMESPACE index a57c38209..03ee7d175 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,7 @@ S3method(print,vertical) export(create_style_guide) export(default_style_guide_attributes) +export(equals_style) export(specify_math_token_spacing) export(specify_reindention) export(style_dir) diff --git a/R/communicate.R b/R/communicate.R index 350f6c312..d61689f4c 100644 --- a/R/communicate.R +++ b/R/communicate.R @@ -27,9 +27,10 @@ communicate_summary <- function(changed, ruler_width) { cli::cat_rule(width = max(40, ruler_width)) } -stop_insufficient_r_version <- function() { - stop(paste0( - "Can't write tree with R version ", getRversion(), - "since data.tree not available. Needs at least R version 3.2." - ), call. = FALSE) +#' @importFrom rlang is_installed +assert_data.tree_installation <- function() { + if (!is_installed("data.tree")) { + stop("The package data.tree needs to be installed for this functionality.") + } } + diff --git a/R/environments.R b/R/environments.R old mode 100755 new mode 100644 index 3964ad824..85968b59d --- a/R/environments.R +++ b/R/environments.R @@ -16,7 +16,7 @@ #' * version 1: Before fix mentioned in #419. #' * version 2: After #419. #' -#'The following utilities are available: +#' The following utilities are available: #' #' * `parser_version_set()` sets the parser version in the environment #' `env_current`. diff --git a/R/io.R b/R/io.R index 404fd09dc..8c2571873 100644 --- a/R/io.R +++ b/R/io.R @@ -20,7 +20,7 @@ transform_utf8_one <- function(path, fun, write_back = write_back) { xfun::write_utf8(new, path) } !identical(unclass(old), unclass(new)) - }, error = function(e) { + }, error = function(e) { warning("When processing ", path, ": ", conditionMessage(e), call. = FALSE) NA }) diff --git a/R/nested-to-tree.R b/R/nested-to-tree.R index 2aa3516d9..48b7db664 100644 --- a/R/nested-to-tree.R +++ b/R/nested-to-tree.R @@ -14,7 +14,7 @@ create_tree <- function(text, structure_only = FALSE) { create_tree_from_pd_with_default_style_attributes <- function(pd, structure_only = FALSE) { pd %>% - create_node_from_nested_root(structure_only) %>% + create_node_from_nested_root(structure_only) %>% as.data.frame() } @@ -29,7 +29,7 @@ create_tree_from_pd_with_default_style_attributes <- function(pd, structure_only #' to check whether two structures are identical. #' @return An object of class "Node" and "R6". #' @examples -#' if (getRversion() >= 3.2) { +#' if (rlang::is_installed("data.tree")) { #' code <- "a <- function(x) { if(x > 1) { 1+1 } else {x} }" #' nested_pd <- styler:::compute_parse_data_nested(code) #' initialized <- styler:::pre_visit(nested_pd, c(default_style_guide_attributes)) @@ -37,7 +37,7 @@ create_tree_from_pd_with_default_style_attributes <- function(pd, structure_only #' } #' @keywords internal create_node_from_nested_root <- function(pd_nested, structure_only) { - if (getRversion() < 3.2) stop_insufficient_r_version() + assert_data.tree_installation() n <- data.tree::Node$new(ifelse( structure_only, "Hierarchical structure", "ROOT (token: short_text [lag_newlines/spaces] {pos_id})" diff --git a/R/parse.R b/R/parse.R index d527f4e43..2b8e1d3b1 100644 --- a/R/parse.R +++ b/R/parse.R @@ -174,7 +174,7 @@ ensure_valid_pd <- function(pd) { non_terminals <- pd %>% filter(terminal == FALSE) valid_pd <- non_terminals$id %>% - map_lgl(~.x %in% pd$parent) %>% + map_lgl(~ .x %in% pd$parent) %>% all() if (!valid_pd) { stop(paste( diff --git a/R/roxygen-examples-add-remove.R b/R/roxygen-examples-add-remove.R index 910cc59f5..addd32b04 100644 --- a/R/roxygen-examples-add-remove.R +++ b/R/roxygen-examples-add-remove.R @@ -36,5 +36,5 @@ remove_roxygen_header <- function(text) { #' @importFrom purrr map_chr add_roxygen_mask <- function(text) { - c(paste0("#' @examples"), map_chr(text, ~paste0("#' ", .x))) + c(paste0("#' @examples"), map_chr(text, ~ paste0("#' ", .x))) } diff --git a/R/rules-other.R b/R/rules-other.R index e24b266e5..a4e750086 100644 --- a/R/rules-other.R +++ b/R/rules-other.R @@ -33,7 +33,7 @@ wrap_if_else_multi_line_in_curly <- function(pd, indent_by = 2) { pd <- pd %>% wrap_if_multiline_curly(indent_by, space_after = ifelse(contains_else_expr(pd), 1, 0) - ) %>% + ) %>% wrap_else_multiline_curly(indent_by, space_after = 0) } pd diff --git a/R/set-assert-args.R b/R/set-assert-args.R index 526a7055c..df705da99 100644 --- a/R/set-assert-args.R +++ b/R/set-assert-args.R @@ -6,11 +6,10 @@ #' @param write_tree Whether or not to write tree. #' @keywords internal set_arg_write_tree <- function(write_tree) { - sufficient_version <- getRversion() >= 3.2 if (is.na(write_tree)) { - write_tree <- ifelse(sufficient_version, TRUE, FALSE) - } else if (!sufficient_version && write_tree) { - stop_insufficient_r_version() + write_tree <- ifelse(is_installed("data.tree"), TRUE, FALSE) + } else if (write_tree) { + assert_data.tree_installation() } write_tree } diff --git a/R/style-guides.R b/R/style-guides.R index 104a1b02a..0833e2fe3 100644 --- a/R/style-guides.R +++ b/R/style-guides.R @@ -347,3 +347,33 @@ tidyverse_math_token_spacing <- function() { one = c("'+'", "'-'", "'*'", "'/'") ) } + + +#' Equals assignment style +#' +#' Use equals assignment instead of arrow assignment. +#' +#' @inheritParams tidyverse_style + +#' @details +#' +#' This style guide is the same as [`tidyverse_style()`], except it uses +#' equals (`=`) rather than arrow `<-` assignment. +#' +#' @family style_guides +#' @examples +#' style_text("x <- 1", style = equals_style) +#' @export +equals_style <- function() { + create_style_guide( + token = list(force_assignment_op_equals), + use_raw_indention = TRUE + ) +} + +force_assignment_op_equals <- function(pd) { + to_replace <- pd$token == "LEFT_ASSIGN" + pd$token[to_replace] <- "EQ_ASSIGN" + pd$text[to_replace] <- "=" + pd +} diff --git a/R/transform-code.R b/R/transform-code.R index c8fc39c77..f289bf779 100644 --- a/R/transform-code.R +++ b/R/transform-code.R @@ -56,12 +56,12 @@ separate_chunks <- function(lines, filetype) { r_raw_chunks <- identify_raw_chunks(lines, filetype = filetype) r_chunks <- map2( - r_raw_chunks$starts, r_raw_chunks$ends, ~lines[seq2(.x + 1, .y - 1)] + r_raw_chunks$starts, r_raw_chunks$ends, ~ lines[seq2(.x + 1, .y - 1)] ) text_chunks <- map2( c(1, r_raw_chunks$ends), c(r_raw_chunks$starts, length(lines)), - ~lines[seq2(.x, .y)] + ~ lines[seq2(.x, .y)] ) lst(r_chunks, text_chunks) } @@ -124,7 +124,7 @@ get_engine_pattern <- function() { #' @inheritParams separate_chunks #' @keywords internal get_knitr_pattern <- function(filetype) { - if(filetype == "Rnw") { + if (filetype == "Rnw") { knitr::all_patterns[["rnw"]] } else if (filetype == "Rmd") { knitr::all_patterns[["md"]] diff --git a/R/ui.R b/R/ui.R index c43895e84..fecf89cfd 100644 --- a/R/ui.R +++ b/R/ui.R @@ -59,7 +59,7 @@ NULL #' @family stylers #' @examples #' \dontrun{ -#' +#' #' style_pkg(style = tidyverse_style, strict = TRUE) #' style_pkg( #' scope = "line_breaks", diff --git a/R/zzz.R b/R/zzz.R index 024f4c6bc..10b074fc4 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,11 +1,10 @@ .onLoad <- function(libname, pkgname) { backports::import(pkgname, "trimws") - op <- options() - op.styler <- list( - styler.colored_print.vertical = TRUE - ) - toset <- !(names(op.styler) %in% names(op)) - if(any(toset)) options(op.styler[toset]) - invisible() + op <- options() + op.styler <- list( + styler.colored_print.vertical = TRUE + ) + toset <- !(names(op.styler) %in% names(op)) + if (any(toset)) options(op.styler[toset]) + invisible() } - diff --git a/README.md b/README.md index a545cd74e..39bbb8009 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,18 @@ +styler +====== -# styler +[![Build Status](https://travis-ci.org/krlmlr/styler.svg?branch=master)](https://travis-ci.org/krlmlr/styler) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/krlmlr/styler?branch=master&svg=true)](https://ci.appveyor.com/project/krlmlr/styler) [![Project Status: WIP - Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](http://www.repostatus.org/badges/latest/wip.svg)](http://www.repostatus.org/#wip) -[![Build -Status](https://travis-ci.org/r-lib/styler.svg?branch=master)](https://travis-ci.org/r-lib/styler) -[![AppVeyor Build -Status](https://ci.appveyor.com/api/projects/status/github/r-lib/styler?branch=master&svg=true)](https://ci.appveyor.com/project/r-lib/styler) -[![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) -[![codecov](https://codecov.io/gh/r-lib/styler/branch/master/graph/badge.svg)](https://codecov.io/gh/r-lib/styler) -[![cran -version](http://www.r-pkg.org/badges/version/styler)](https://cran.r-project.org/package=styler) - -The goal of styler is to provide non-invasive pretty-printing of R -source code while adhering to the -[tidyverse](http://style.tidyverse.org) formatting rules. styler can be -customized to format code according to other style guides too. - -## Installation - -You can install the package from CRAN: - -``` r -install.packages("styler") -``` - -Or get the development version from GitHub: - -``` r -# install.packages("remotes") -remotes::install_github("r-lib/styler") -``` - -## API +The goal of styler is to provide non-invasive pretty-printing of R source code while adhering to the [tidyverse](https://github.com/tidyverse/style) formatting rules. Support for custom style guides is planned. You can style a simple character vector of code with `style_text()`: ``` r -library("styler") -ugly_code <- "a=function( x){1+1} " -style_text(ugly_code) +ugly_code <- "a<-function( x){1+1} " +style_text(ugly_code) %>% + cat(sep = "\n") #> a <- function(x) { #> 1 + 1 #> } @@ -47,98 +20,11 @@ style_text(ugly_code) There are a few variants of `style_text()`: - - `style_file()` styles .R and/or .Rmd files. - - `style_dir()` styles all .R and/or .Rmd files in a directory. - - `style_pkg()` styles the source files of an R package. - - RStudio Addins for styling the active file, styling the current - package and styling the highlighted code -region. +- `style_file()` styles a single .R file. +- `style_dir()` styles all .R files in a directory. +- `style_pkg()` styles the source files of an R package. +- An RStudio Addin that styles the active file .R file -## Functionality of styler - -**scope** - -You can decide on the level of invasiveness with the scope argument. You -can style: - - - just spaces. - - spaces and indention. - - spaces, indention and line breaks. - - spaces, indention, line breaks and tokens. - - - -``` r -ugly_code <- "a=function( x){1+1} " -style_text(ugly_code, scope = "spaces") -#> a = function(x) {1 + 1} -``` - -Note that compared to the default used above `scope = "tokens"`: - - - no line breaks were added. - - `<-` was not replaced with `=`. - -While spaces still got styled (around `=` in `(x)`). - -**strict** - -If you wish to keep alignment as is, you can use `strict = FALSE`: - -``` r -style_text( - c( - "first <- 4", - "second <- 1+1" - ), - strict = FALSE -) -#> first <- 4 -#> second <- 1 + 1 -``` - -This was just the tip of the iceberg. Learn more about customization -with the tidyverse style guide in in this -[vignette](http://styler.r-lib.org/articles/introducing_styler.html). If -this is not flexible enough for you, you can implement your own style -guide, as explained in the corresponding -[vignette](http://styler.r-lib.org/articles/customizing_styler.html). - -## Adaption of styler - -styler functionality is made available through other packages, most -notably - - - `usethis::use_tidy_style()` styles your project according to the - tidyverse style guide. - - `reprex::reprex(style = TRUE)` to prettify reprex code before - printing. To permanently use `style = TRUE` without specifying it - every time, you can add the following line to your `.Rprofile` (via - `usethis::edit_r_profile()`): `options(reprex.styler = TRUE)`. - - you can pretty-print your R code in RMarkdown reports without having - styler modifying the source. This feature is implemented as a code - chunk option in knitr. use `tidy = "styler"` in the header of a code - chunks (e.g. ` ```{r name-of-the-chunk, tidy = "styler"}`), or - `knitr::opts_chunk$set(tidy = "styler")` at the top of your - RMarkdown script. - - pretty-printing of [drake](https://github.com/ropensci/drake) - workflow data frames with `drake::drake_plan_source()`. - -## Further resources - - - The official [web documentation](http://styler.r-lib.org/) of - styler, containing various vignettes function documentation as well - as a change-log. - - [Blog - post](https://lorenzwalthert.netlify.com/posts/customizing-styler-the-quick-way/) - about how you can customize styler without being an expert. - - A [tidyverse.org blog - post](https://www.tidyverse.org/articles/2017/12/styler-1.0.0/) - introducing the functionality of styler. - - The wiki of [Google Summer of Code - 2017](https://github.com/rstats-gsoc/gsoc2017/wiki/Noninvasive-source-code-formatting) - or the [pkgdown](https://r-lib.github.io/styler/) page contain - information related to the initial development phase during Google - Summer of Code 2017. +You can find more information on the wiki of [Google Summer of Code 2017](https://github.com/rstats-gsoc/gsoc2017/wiki/Noninvasive-source-code-formatting) or check out the [pkgdown](https://krlmlr.github.io/styler/) page. diff --git a/derby.log b/derby.log new file mode 100644 index 000000000..33784b4ea --- /dev/null +++ b/derby.log @@ -0,0 +1,13 @@ +---------------------------------------------------------------- +Fri Jun 23 14:57:19 CEST 2017: +Booting Derby version The Apache Software Foundation - Apache Derby - 10.10.1.1 - (1458268): instance a816c00e-015c-d507-3867-00002e8b9ff0 +on database directory memory:/home/muelleki/git/R/styler/databaseName=metastore_db with class loader org.apache.spark.sql.hive.client.IsolatedClientLoader$$anon$1@26ce3a2 +Loaded from file:/home/muelleki/.cache/spark/spark-1.6.2-bin-hadoop2.6/lib/spark-assembly-1.6.2-hadoop2.6.0.jar +java.vendor=Oracle Corporation +java.runtime.version=1.8.0_131-8u131-b11-0ubuntu1.17.04.1-b11 +user.dir=/home/muelleki/git/R/styler +os.name=Linux +os.arch=amd64 +os.version=4.10.0-24-generic +derby.system.home=null +Database Class Loader started - derby.database.classpath='' diff --git a/docs/articles/data_structures.Rmd b/docs/articles/data_structures.Rmd new file mode 100644 index 000000000..b0bd31edb --- /dev/null +++ b/docs/articles/data_structures.Rmd @@ -0,0 +1,153 @@ +--- +title: "Data Structures" +author: "Lorenz Walthert" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Vignette Title} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +This vignette illustrates how the core of `styler` currently^[at commit `e6ddee0f510d3c9e3e22ef68586068fa5c6bc140`] works, i.e. how +rules are applied to a parse table and how limitations of this approach can be +overcome with a refined approach. + +## Status quo - the flat approach + +Roughly speaking, a string containing code to be formatted is parsed with `parse` +and the output is passed to `getParseData` in order to obtain a parse +table with detailed information about every token. For a simple example string +"`a <- function(x) { if(x > 1) { 1+1 } else {x} }`" to be formatted, the parse +table on which `styler` performs the manipulations looks similar to the one +presented below. + +```{r, message = FALSE} +library("styler") +library("dplyr") + +code <- "a <- function(x) { if(x > 1) { 1+1 } else {x} }" + +(parse_table <- styler:::compute_parse_data_flat_enhanced(code)) +``` +The column `spaces` was computed from the columns `col1` and `col2`, `newlines` +was computed from `line1` and `line2` respectively. + +So far, styler can set the spaces around the operators correctly. In our example, +that involves adding spaces around `+`, so in the `spaces` column, element nine +and ten must be set to one. This means that a space is added after `1` and after `+`. +To get the spacing right and cover the various cases, a set of functions has to +be applied to the parse table subsequently (and in the right order), +which is essentially done via `Reduce()`. +After all modifications on the table are completed, `serialize_parse_data()` +collapses the `text` column and adds the number of spaces and +line breaks specified in `spaces` and `newlines` in between the elements of +`text`. If we serialize our table and don't perform any modification, we +obviously just get back what we started with. +```{r} +styler:::serialize_parse_data_flat(parse_table) +``` + +## Refining the flat approach - nesting the parse table + +Although the flat approach is good place to start, e.g. for fixing spaces +between operators, it has its limitations. In particular, it treats each token +the same way in the sense that it does not account for the context of the token, +i.e. in which sub-expression it appears. +To set the indention correctly, we need a hierarchical view on the parse data, +since all tokens in a sub-expression have the same indention level. Hence, +a natural approach would be to create a nested parse table instead of a flat +parse table and then take a recursion over all elements in the table, so for +each sub(-sub etc.)-expression, a separate parse table would be created and the +modifications would be applied to this table before putting everything back +together. A function to create a nested parse table already exists in `styler`. +Let's have a look at the top level: + +```{r} +(l1 <- styler:::compute_parse_data_nested(code)[-1]) + +``` + +The tibble contains the column `child`, which itself contains a tibble. +If we "enter" the first child, we can see that the expression was split up +further. + +```{r} +l1$child[[1]] %>% + select(text, terminal, child, token) +``` + +And further... +```{r} +l1$child[[1]]$child[[3]]$child[[5]] +``` + +... and so on. Every child that is not a terminal contains another tibble where +the sub-expression is split up further - until we are left with tibbles that +only contain terminals. + + +Recall the above example. `a <- function(x) { if(x > 1) { 1+1 } else {x} }`. +In the last printed parse table, we can see that see that the whole if condition +is a sub-expression of `code`, surrounded by two curly brackets. Hence, +one would like to set the indention level for this sub-expression before +doing anything with it in more detail. Later, when we progressed deeper into +the nested table, we hit a similar pattern: + +```{r} +l1$child[[1]]$child[[3]]$child[[5]]$child[[2]]$child[[5]] +``` +Again, we have two curly brackets and an expression inside. We would like to +set the indention level for the expression `1+1` in the same way as for the +whole if condition. + +The simple example above makes it evident that a recursive approach to this +problem would be the most natural. + +The code for a function that kind of sketches the idea and illustrates such a +recursion is given below. + +It takes a nested parse table as input and then does the recursion over all +children. If the child is a terminal, it returns the text, otherwise, +it "enters" the child to find the terminals inside of the child and returns them. + +```{r} +serialize <- function(x) { + out <- Map( + function(terminal, text, child) { + if (terminal) + text + else + serialize(child) + }, + x$terminal, x$text, x$child + ) + out +} + +x <- styler:::compute_parse_data_nested(code) +serialize(x) %>% unlist +``` + +How to exactly implement a similar recursion to not just return each text +token separately, but +the styled text as one string (or one string per line) is subject to future work, +so would be the functions to be +applied to a sub-expression parse table that create correct indention. +Similar to `compute_parse_data_flat_enhanced`, the column `spaces` and `newlines` +would be required to be computed by `compute_parse_data_nested` as well as a +new column `indention`. + + +## Final Remarks + +Although a flat structure would possibly also allow us to solve the problem of +indention, it is a less elegant and flexible solution to the problem. It would +involve looking for an opening curly bracket in the parse table, set the +indention level for all subsequent rows in the parse table until the next +opening or closing curly bracket is hit and then intending one level further or +setting indention back to where it was at the beginning of the table. + +Note that the vignette just addressed the question of indention caused by +curly brackets and has not dealt with other operators that would trigger +indention, such as `(` or `+`. diff --git a/docs/articles/data_structures.html b/docs/articles/data_structures.html new file mode 100644 index 000000000..ee6d8b75b --- /dev/null +++ b/docs/articles/data_structures.html @@ -0,0 +1,208 @@ + + + + + + + +Data Structures • styler + + + + + + +
+
+ + + +
+
+ + + + +
+

This vignette illustrates how the core of styler currently1 works, i.e. how rules are applied to a parse table and how limitations of this approach can be overcome with a refined approach.

+
+

+Status quo - the flat approach

+

Roughly speaking, a string containing code to be formatted is parsed with parse and the output is passed to getParseData in order to obtain a parse table with detailed information about every token. For a simple example string “a <- function(x) { if(x > 1) { 1+1 } else {x} }” to be formatted, the parse table on which styler performs the manipulations looks similar to the one presented below.

+
library("styler")
+library("dplyr")
+
+code <- "a <- function(x) { if(x > 1) { 1+1 } else {x} }"
+
+(parse_table <- styler:::compute_parse_data_flat_enhanced(code))
+
## # A tibble: 24 x 13
+##    line1  col1 line2  col2          token     text terminal short newlines
+##    <int> <int> <int> <int>          <chr>    <chr>    <lgl> <chr>    <int>
+##  1     1     0     1     0          START                NA  <NA>        0
+##  2     1     1     1     1         SYMBOL        a     TRUE     a        0
+##  3     1     3     1     4    LEFT_ASSIGN       <-     TRUE    <-        0
+##  4     1     6     1    13       FUNCTION function     TRUE funct        0
+##  5     1    14     1    14            '('        (     TRUE     (        0
+##  6     1    15     1    15 SYMBOL_FORMALS        x     TRUE     x        0
+##  7     1    16     1    16            ')'        )     TRUE     )        0
+##  8     1    18     1    18            '{'        {     TRUE     {        0
+##  9     1    20     1    21             IF       if     TRUE    if        0
+## 10     1    22     1    22            '('        (     TRUE     (        0
+## # ... with 14 more rows, and 4 more variables: lag_newlines <dbl>,
+## #   spaces <int>, multi_line <lgl>, indent <dbl>
+

The column spaces was computed from the columns col1 and col2, newlines was computed from line1 and line2 respectively.

+

So far, styler can set the spaces around the operators correctly. In our example, that involves adding spaces around +, so in the spaces column, element nine and ten must be set to one. This means that a space is added after 1 and after +. To get the spacing right and cover the various cases, a set of functions has to be applied to the parse table subsequently (and in the right order), which is essentially done via Reduce(). After all modifications on the table are completed, serialize_parse_data() collapses the text column and adds the number of spaces and line breaks specified in spaces and newlines in between the elements of text. If we serialize our table and don’t perform any modification, we obviously just get back what we started with.

+
styler:::serialize_parse_data_flat(parse_table)
+
## [1] "a <- function(x) { if(x > 1) { 1+1 } else {x} }"
+
+
+

+Refining the flat approach - nesting the parse table

+

Although the flat approach is good place to start, e.g. for fixing spaces between operators, it has its limitations. In particular, it treats each token the same way in the sense that it does not account for the context of the token, i.e. in which sub-expression it appears. To set the indention correctly, we need a hierarchical view on the parse data, since all tokens in a sub-expression have the same indention level. Hence, a natural approach would be to create a nested parse table instead of a flat parse table and then take a recursion over all elements in the table, so for each sub(-sub etc.)-expression, a separate parse table would be created and the modifications would be applied to this table before putting everything back together. A function to create a nested parse table already exists in styler. Let’s have a look at the top level:

+
(l1 <- styler:::compute_parse_data_nested(code)[-1])
+
## # A tibble: 1 x 13
+##    col1 line2  col2    id parent token terminal  text short token_before
+##   <int> <int> <int> <int>  <int> <chr>    <lgl> <chr> <chr>        <chr>
+## 1     1     1    47    49      0  expr    FALSE                     <NA>
+## # ... with 3 more variables: token_after <chr>, internal <lgl>,
+## #   child <list>
+

The tibble contains the column child, which itself contains a tibble. If we “enter” the first child, we can see that the expression was split up further.

+
l1$child[[1]] %>%
+  select(text, terminal, child, token)
+
## # A tibble: 3 x 4
+##    text terminal             child       token
+##   <chr>    <lgl>            <list>       <chr>
+## 1          FALSE <tibble [1 x 14]>        expr
+## 2    <-     TRUE            <NULL> LEFT_ASSIGN
+## 3          FALSE <tibble [5 x 14]>        expr
+

And further…

+
l1$child[[1]]$child[[3]]$child[[5]]
+
## # A tibble: 3 x 14
+##   line1  col1 line2  col2    id parent token terminal  text short
+##   <int> <int> <int> <int> <int>  <int> <chr>    <lgl> <chr> <chr>
+## 1     1    18     1    18     9     45   '{'     TRUE     {     {
+## 2     1    20     1    45    42     45  expr    FALSE            
+## 3     1    47     1    47    40     45   '}'     TRUE     }     }
+## # ... with 4 more variables: token_before <chr>, token_after <chr>,
+## #   internal <lgl>, child <list>
+

… and so on. Every child that is not a terminal contains another tibble where the sub-expression is split up further - until we are left with tibbles that only contain terminals.

+

Recall the above example. a <- function(x) { if(x > 1) { 1+1 } else {x} }. In the last printed parse table, we can see that see that the whole if condition is a sub-expression of code, surrounded by two curly brackets. Hence, one would like to set the indention level for this sub-expression before doing anything with it in more detail. Later, when we progressed deeper into the nested table, we hit a similar pattern:

+
l1$child[[1]]$child[[3]]$child[[5]]$child[[2]]$child[[5]]
+
## # A tibble: 3 x 14
+##   line1  col1 line2  col2    id parent token terminal  text short
+##   <int> <int> <int> <int> <int>  <int> <chr>    <lgl> <chr> <chr>
+## 1     1    30     1    30    20     30   '{'     TRUE     {     {
+## 2     1    32     1    34    27     30  expr    FALSE            
+## 3     1    36     1    36    26     30   '}'     TRUE     }     }
+## # ... with 4 more variables: token_before <chr>, token_after <chr>,
+## #   internal <lgl>, child <list>
+

Again, we have two curly brackets and an expression inside. We would like to set the indention level for the expression 1+1 in the same way as for the whole if condition.

+

The simple example above makes it evident that a recursive approach to this problem would be the most natural.

+

The code for a function that kind of sketches the idea and illustrates such a recursion is given below.

+

It takes a nested parse table as input and then does the recursion over all children. If the child is a terminal, it returns the text, otherwise, it “enters” the child to find the terminals inside of the child and returns them.

+
serialize <- function(x) {
+  out <- Map(
+    function(terminal, text, child) {
+      if (terminal)
+        text
+      else
+        serialize(child)
+    },
+    x$terminal, x$text, x$child
+  )
+  out
+}
+
+x <- styler:::compute_parse_data_nested(code)
+serialize(x) %>% unlist
+
##  [1] "a"        "<-"       "function" "("        "x"        ")"       
+##  [7] "{"        "if"       "("        "x"        ">"        "1"       
+## [13] ")"        "{"        "1"        "+"        "1"        "}"       
+## [19] "else"     "{"        "x"        "}"        "}"
+

How to exactly implement a similar recursion to not just return each text token separately, but the styled text as one string (or one string per line) is subject to future work, so would be the functions to be applied to a sub-expression parse table that create correct indention. Similar to compute_parse_data_flat_enhanced, the column spaces and newlines would be required to be computed by compute_parse_data_nested as well as a new column indention.

+
+
+

+Final Remarks

+

Although a flat structure would possibly also allow us to solve the problem of indention, it is a less elegant and flexible solution to the problem. It would involve looking for an opening curly bracket in the parse table, set the indention level for all subsequent rows in the parse table until the next opening or closing curly bracket is hit and then intending one level further or setting indention back to where it was at the beginning of the table.

+

Note that the vignette just addressed the question of indention caused by curly brackets and has not dealt with other operators that would trigger indention, such as ( or +.

+
+
+
+
    +
  1. at commit e6ddee0f510d3c9e3e22ef68586068fa5c6bc140

  2. +
+
+
+
+ + + +
+ + + +
+ + + diff --git a/docs/articles/index.html b/docs/articles/index.html new file mode 100644 index 000000000..ef1bfec9b --- /dev/null +++ b/docs/articles/index.html @@ -0,0 +1,111 @@ + + + + + + + + +Articles • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +
+
+ + +
+ + + diff --git a/docs/articles/manipulating_nested_parse_data.Rmd b/docs/articles/manipulating_nested_parse_data.Rmd new file mode 100644 index 000000000..5e6befc9d --- /dev/null +++ b/docs/articles/manipulating_nested_parse_data.Rmd @@ -0,0 +1,134 @@ +--- +title: "Manipulating the nested Parse Table" +author: "Lorenz Walthert" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Vignette Title} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- +```{r, message=FALSE} +library("dplyr") +library("purrr") +pkgload::load_all() +``` + +This vignette builds on the vignette "Data Structures" and discusses how +to go forward with the nested structure of the parse data. +In order to compute the white space information in a nested data structure, we +need a recursion. We use a +[visitor approach](https://en.wikipedia.org/wiki/Visitor_pattern) to separate +the algorithm (computing white space information) from the object (nested) +data structure. +The function `create_filler()` can then be used to add +white space information on every level of nesting within the nested parse data +if applied in combination with the visitor. `visitor()` takes a object to +operate on and a list of functions. Each function is applied at the current +level of nesting before the next level of nesting is entered. +```{r} +pre_visit +visit_one +``` +This comes with two advantages. + +* We don't need a *_nested() version of every function we want to apply to the + parse tables, in particular the rules in R/rules.R +* We go through the whole structure only once (instead of every *_nested() + function going through it once, which is more efficient in terms of speed. + +`create_filler()` was adapted to also initialize indention and lag_newlines. +```{r} +create_filler +``` + +```{r} +code <- "a <- function(x) { if(x > 1) { 1+1 } else {x} }" +pd_nested <- compute_parse_data_nested(code) +pd_nested_enhanced <- pre_visit(pd_nested, c(create_filler)) +pd_nested_enhanced +``` + + +As a next step, we need to find a way to serialize the nested tibble, or in +other words, to transform it to its character vector representation. As a +starting point, consider the function `serialize` that was introduced in the +vignette "Data Structures". + +```{r} +serialize <- function(x) { + out <- Map( + function(terminal, text, child) { + if (terminal) + text + else + serialize(child) + }, + x$terminal, x$text, x$child + ) + out +} + +serialize(pd_nested) %>% unlist +``` + +`serialize` can be combined with `serialize_parse_data_flat`. The latter +pastes together the column "text" of a flat parse table by taking into account +space and line break information, splits the string by line break and returns it. +```{r} +serialize_parse_data_flat +``` + + +However, things get a bit more complicated, mainly because line break and white +space information is not only contained in the terminal tibbles of the nested +parse data, but even before, as the following example shows. +```{r} +pd_nested_enhanced$child[[1]] +pd_nested_enhanced$child[[1]]$child[[1]] +``` +After "a" in `code`, there is a space, but this information is not contained in the +tibble where we find the terminal "a". In general, we must add newlines +and spaces values *after* we computed character vector representation of the +expression. In our example: we know that there is a space after the non-terminal +"a" by looking at `pd_nested_enhanced$child[[1]]`. Therefore, we need to add +this space to the very last terminal within `pd_nested_enhanced$child[[1]]` before we +collapse everything together. +```{r} +serialize_parse_data_nested_helper + +serialize_parse_data_nested +``` +Before we are done, we need to add information regarding indention to the parse +table. We can add indention after every line break that comes after a round +bracket with `indent_round()`. And then serialize it. +```{r} +pre_visit(pd_nested, + c(create_filler, + purrr::partial(indent_round, indent_by = 2))) +``` + +We can see how indention works with a more complicated example +```{r} +indented <- c( + "call(", + " 1,", + " call2(", + " 2, 3,", + " call3(1, 2, 22),", + " 5", + " ),", + " 144", + ")" +) + +not_indented <- trimws(indented) +back_and_forth <- not_indented %>% + compute_parse_data_nested() %>% + pre_visit(c(create_filler, + purrr::partial(indent_round, indent_by = 2))) %>% + serialize_parse_data_nested() + +identical(indented, back_and_forth) +``` + diff --git a/docs/articles/manipulating_nested_parse_data.html b/docs/articles/manipulating_nested_parse_data.html new file mode 100644 index 000000000..42217f506 --- /dev/null +++ b/docs/articles/manipulating_nested_parse_data.html @@ -0,0 +1,270 @@ + + + + + + + +Manipulating the nested Parse Table • styler + + + + + + +
+
+ + + +
+
+ + + + +
+
library("dplyr")
+library("purrr")
+pkgload::load_all()
+

This vignette builds on the vignette “Data Structures” and discusses how to go forward with the nested structure of the parse data. In order to compute the white space information in a nested data structure, we need a recursion. We use a visitor approach to separate the algorithm (computing white space information) from the object (nested) data structure. The function create_filler() can then be used to add white space information on every level of nesting within the nested parse data if applied in combination with the visitor. visitor() takes a object to operate on and a list of functions. Each function is applied at the current level of nesting before the next level of nesting is entered.

+
pre_visit
+
## function(pd_nested, funs) {
+##   if (is.null(pd_nested)) return()
+##   pd_transformed <- visit_one(pd_nested, funs)
+## 
+##   pd_transformed$child <- map(pd_transformed$child, pre_visit, funs = funs)
+##   pd_transformed
+## }
+## <environment: namespace:styler>
+
visit_one
+
## function(pd_flat, funs) {
+##   reduce(funs, function(x, fun) fun(x),
+##          .init = pd_flat)
+## }
+## <environment: namespace:styler>
+

This comes with two advantages.

+
    +
  • We don’t need a *_nested() version of every function we want to apply to the parse tables, in particular the rules in R/rules.R
  • +
  • We go through the whole structure only once (instead of every *_nested() function going through it once, which is more efficient in terms of speed.
  • +
+

create_filler() was adapted to also initialize indention and lag_newlines.

+
create_filler
+
## function(pd_flat) {
+## 
+##   pd_flat$line3 <- lead(pd_flat$line1, default = tail(pd_flat$line2, 1))
+##   pd_flat$col3 <- lead(pd_flat$col1, default = tail(pd_flat$col2, 1) + 1L)
+##   pd_flat$newlines <- pd_flat$line3 - pd_flat$line2
+##   pd_flat$lag_newlines <- lag(pd_flat$newlines, default = 0)
+##   pd_flat$col2_nl <- if_else(pd_flat$newlines > 0L, 0L, pd_flat$col2)
+##   pd_flat$spaces <- pd_flat$col3 - pd_flat$col2_nl - 1L
+##   pd_flat$multi_line <- ifelse(pd_flat$terminal, FALSE, NA)
+## 
+##   ret <- pd_flat[, !(names(pd_flat) %in% c("line3", "col3", "col2_nl"))]
+## 
+## 
+##   if (!("indent" %in% names(ret))) {
+##     ret$indent <- 0
+##   }
+## 
+##   if (any(ret$spaces < 0L)) {
+##     stop("Invalid parse data")
+##   }
+## 
+##   ret
+## }
+## <environment: namespace:styler>
+
code <- "a <- function(x) { if(x > 1) { 1+1 } else {x} }"
+pd_nested <- compute_parse_data_nested(code)
+pd_nested_enhanced <- pre_visit(pd_nested, c(create_filler))
+pd_nested_enhanced
+
## # A tibble: 1 x 19
+##   line1  col1 line2  col2    id parent token terminal  text short
+##   <int> <int> <int> <int> <int>  <int> <chr>    <lgl> <chr> <chr>
+## 1     1     1     1    47    49      0  expr    FALSE            
+## # ... with 9 more variables: token_before <chr>, token_after <chr>,
+## #   internal <lgl>, child <list>, newlines <int>, lag_newlines <dbl>,
+## #   spaces <int>, multi_line <lgl>, indent <dbl>
+

As a next step, we need to find a way to serialize the nested tibble, or in other words, to transform it to its character vector representation. As a starting point, consider the function serialize that was introduced in the vignette “Data Structures”.

+
serialize <- function(x) {
+  out <- Map(
+    function(terminal, text, child) {
+      if (terminal)
+        text
+      else
+        serialize(child)
+    },
+    x$terminal, x$text, x$child
+  )
+  out
+}
+
+serialize(pd_nested) %>% unlist
+
##  [1] "a"        "<-"       "function" "("        "x"        ")"       
+##  [7] "{"        "if"       "("        "x"        ">"        "1"       
+## [13] ")"        "{"        "1"        "+"        "1"        "}"       
+## [19] "else"     "{"        "x"        "}"        "}"
+

serialize can be combined with serialize_parse_data_flat. The latter pastes together the column “text” of a flat parse table by taking into account space and line break information, splits the string by line break and returns it.

+
serialize_parse_data_flat
+
## function(pd_flat) {
+##   pd_flat %>%
+##     summarize_(
+##       text_ws = ~paste0(
+##         text, newlines_and_spaces(newlines, spaces),
+##         collapse = "")) %>%
+##     .[["text_ws"]] %>%
+##     strsplit("\\n", fixed = TRUE) %>%
+##     .[[1L]]
+## }
+## <environment: namespace:styler>
+

However, things get a bit more complicated, mainly because line break and white space information is not only contained in the terminal tibbles of the nested parse data, but even before, as the following example shows.

+
pd_nested_enhanced$child[[1]]
+
## # A tibble: 3 x 19
+##   line1  col1 line2  col2    id parent       token terminal  text short
+##   <int> <int> <int> <int> <int>  <int>       <chr>    <lgl> <chr> <chr>
+## 1     1     1     1     1     3     49        expr    FALSE            
+## 2     1     3     1     4     2     49 LEFT_ASSIGN     TRUE    <-    <-
+## 3     1     6     1    47    48     49        expr    FALSE            
+## # ... with 9 more variables: token_before <chr>, token_after <chr>,
+## #   internal <lgl>, child <list>, newlines <int>, lag_newlines <dbl>,
+## #   spaces <int>, multi_line <lgl>, indent <dbl>
+
pd_nested_enhanced$child[[1]]$child[[1]]
+
## # A tibble: 1 x 19
+##   line1  col1 line2  col2    id parent  token terminal  text short
+##   <int> <int> <int> <int> <int>  <int>  <chr>    <lgl> <chr> <chr>
+## 1     1     1     1     1     1      3 SYMBOL     TRUE     a     a
+## # ... with 9 more variables: token_before <chr>, token_after <chr>,
+## #   child <list>, internal <lgl>, newlines <int>, lag_newlines <dbl>,
+## #   spaces <int>, multi_line <lgl>, indent <dbl>
+

After “a” in code, there is a space, but this information is not contained in the tibble where we find the terminal “a”. In general, we must add newlines and spaces values after we computed character vector representation of the expression. In our example: we know that there is a space after the non-terminal “a” by looking at pd_nested_enhanced$child[[1]]. Therefore, we need to add this space to the very last terminal within pd_nested_enhanced$child[[1]] before we collapse everything together.

+
serialize_parse_data_nested_helper
+
## function(pd_nested, pass_indent) {
+##   out <- pmap(list(pd_nested$terminal, pd_nested$text, pd_nested$child,
+##                    pd_nested$spaces, pd_nested$lag_newlines, pd_nested$indent),
+##               function(terminal, text, child, spaces, lag_newlines, indent) {
+##                 total_indent <- pass_indent + indent
+##                 preceding_linebreak <- if_else(lag_newlines > 0, 1, 0)
+##                 if (terminal) {
+##                   c(add_newlines(lag_newlines),
+##                     add_spaces(total_indent * preceding_linebreak),
+##                     text,
+##                     add_spaces(spaces))
+##                 } else {
+##                   c(add_newlines(lag_newlines),
+##                     add_spaces(total_indent * preceding_linebreak),
+##                     serialize_parse_data_nested_helper(child, total_indent),
+##                     add_spaces(spaces))
+##                 }
+##               }
+##   )
+##   out
+## }
+## <environment: namespace:styler>
+
serialize_parse_data_nested
+
## function(pd_nested) {
+##   out <- c(add_newlines(start_on_line(pd_nested) - 1),
+##            serialize_parse_data_nested_helper(pd_nested, pass_indent = 0)) %>%
+##     unlist() %>%
+##     paste0(collapse = "") %>%
+##     strsplit("\\n", fixed = TRUE) %>%
+##     .[[1L]]
+##   out
+## }
+## <environment: namespace:styler>
+

Before we are done, we need to add information regarding indention to the parse table. We can add indention after every line break that comes after a round bracket with indent_round(). And then serialize it.

+
pre_visit(pd_nested, 
+               c(create_filler, 
+                 purrr::partial(indent_round, indent_by = 2)))
+
## # A tibble: 1 x 19
+##   line1  col1 line2  col2    id parent token terminal  text short
+##   <int> <int> <int> <int> <int>  <int> <chr>    <lgl> <chr> <chr>
+## 1     1     1     1    47    49      0  expr    FALSE            
+## # ... with 9 more variables: token_before <chr>, token_after <chr>,
+## #   internal <lgl>, child <list>, newlines <int>, lag_newlines <dbl>,
+## #   spaces <int>, multi_line <lgl>, indent <dbl>
+

We can see how indention works with a more complicated example

+
indented <- c(
+  "call(", 
+  "  1,", 
+  "  call2(", 
+  "    2, 3,", 
+  "    call3(1, 2, 22),", 
+  "    5", 
+  "  ),", 
+  "  144",
+  ")"
+)
+
+not_indented <- trimws(indented)
+back_and_forth <- not_indented %>%
+  compute_parse_data_nested() %>%
+  pre_visit(c(create_filler, 
+        purrr::partial(indent_round, indent_by = 2))) %>%
+  serialize_parse_data_nested()
+
+identical(indented, back_and_forth)
+
## [1] TRUE
+
+
+ + + +
+ + + +
+ + + diff --git a/docs/articles/performance_improvements.Rmd b/docs/articles/performance_improvements.Rmd new file mode 100644 index 000000000..35338100a --- /dev/null +++ b/docs/articles/performance_improvements.Rmd @@ -0,0 +1,66 @@ +--- +title: "Performance Improvements" +author: "Lorenz Walthert" +date: "7/24/2017" +output: html_document +--- + +We want to make styler faster. + +```{r} +library(styler) +microbenchmark::microbenchmark( + base = style_file("tests/testthat/indention_multiple/overall-in.R"), + times = 2 +) +#> Unit: seconds +#> expr min lq mean median uq max neval +#> base 4.131253 4.131253 4.172017 4.172017 4.212781 4.212781 2 +``` + +Replacing mutate statments. +```{r} +microbenchmark::microbenchmark( + base = style_file("tests/testthat/indention_multiple/overall-in.R"), + times = 2 +) +#> Unit: seconds +#> expr min lq mean median uq max neval +#> base 2.13616 2.13616 2.223659 2.223659 2.311158 2.311158 2 +``` + +Move `opening` argument out of needs indention. +```{r} +microbenchmark::microbenchmark( + base = style_file("tests/testthat/indention_multiple/overall-in.R"), + times = 5 +) + +#> Unit: seconds +#> expr min lq mean median uq max neval +#> base 2.18097 2.184721 2.225294 2.200893 2.241799 2.318089 5 +``` + +Dropping unnecessary select and arrange stuffstatments +```{r} +microbenchmark::microbenchmark( + base = style_file("tests/testthat/indention_multiple/overall-in.R"), + times = 5 +) +#> Unit: seconds +#> expr min lq mean median uq max neval +#> base 2.109271 2.134377 2.147821 2.158567 2.165384 2.171505 5 +``` + + +Some more stuff (early return, purr) +```{r} +microbenchmark::microbenchmark( + base = style_file("tests/testthat/indention_multiple/overall-in.R"), + times = 5 +) +#> Unit: milliseconds +#> expr min lq mean median uq max neval +#> base 930.4391 944.9253 969.2838 951.4632 951.6571 1067.934 5 +``` + diff --git a/docs/authors.html b/docs/authors.html new file mode 100644 index 000000000..69fd9b36a --- /dev/null +++ b/docs/authors.html @@ -0,0 +1,111 @@ + + + + + + + + +Authors • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
    +
  • +

    Kirill Müller. Author, maintainer. +

    +
  • +
+ +
+ +
+ + + +
+ + + diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 000000000..092d1d3e3 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,131 @@ + + + + + + + +Non-invasive Pretty Printing of R code • styler + + + + + + +
+
+ + + +
+
+ + + + +
+ +
+ + +

The goal of styler is to provide non-invasive pretty-printing of R source code while adhering to the tidyverse formatting rules. Support for custom style guides is planned.

+

You can style a simple character vector of code with style_text():

+
ugly_code <- "a<-function( x){1+1}           "
+style_text(ugly_code) %>%
+  cat(sep = "\n")
+#> a <- function(x) {
+#>   1 + 1
+#> }
+

There are a few variants of style_text():

+
    +
  • +style_file() styles a single .R file.
  • +
  • +style_dir() styles all .R files in a directory.
  • +
  • +style_pkg() styles the source files of an R package.
  • +
  • An RStudio Addin that styles the active file .R file
  • +
+

+

You can find more information on the wiki of Google Summer of Code 2017 or check out the pkgdown page.

+
+
+
+ + + +
+ + + +
+ + + diff --git a/docs/jquery.sticky-kit.min.js b/docs/jquery.sticky-kit.min.js new file mode 100644 index 000000000..e2a3c6de9 --- /dev/null +++ b/docs/jquery.sticky-kit.min.js @@ -0,0 +1,9 @@ +/* + Sticky-kit v1.1.2 | WTFPL | Leaf Corcoran 2015 | http://leafo.net +*/ +(function(){var b,f;b=this.jQuery||window.jQuery;f=b(window);b.fn.stick_in_parent=function(d){var A,w,J,n,B,K,p,q,k,E,t;null==d&&(d={});t=d.sticky_class;B=d.inner_scrolling;E=d.recalc_every;k=d.parent;q=d.offset_top;p=d.spacer;w=d.bottoming;null==q&&(q=0);null==k&&(k=void 0);null==B&&(B=!0);null==t&&(t="is_stuck");A=b(document);null==w&&(w=!0);J=function(a,d,n,C,F,u,r,G){var v,H,m,D,I,c,g,x,y,z,h,l;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);I=A.height();g=a.parent();null!=k&&(g=g.closest(k)); +if(!g.length)throw"failed to find stick parent";v=m=!1;(h=null!=p?p&&a.closest(p):b("
"))&&h.css("position",a.css("position"));x=function(){var c,f,e;if(!G&&(I=A.height(),c=parseInt(g.css("border-top-width"),10),f=parseInt(g.css("padding-top"),10),d=parseInt(g.css("padding-bottom"),10),n=g.offset().top+c+f,C=g.height(),m&&(v=m=!1,null==p&&(a.insertAfter(h),h.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(t),e=!0),F=a.offset().top-(parseInt(a.css("margin-top"),10)||0)-q, +u=a.outerHeight(!0),r=a.css("float"),h&&h.css({width:a.outerWidth(!0),height:u,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),e))return l()};x();if(u!==C)return D=void 0,c=q,z=E,l=function(){var b,l,e,k;if(!G&&(e=!1,null!=z&&(--z,0>=z&&(z=E,x(),e=!0)),e||A.height()===I||x(),e=f.scrollTop(),null!=D&&(l=e-D),D=e,m?(w&&(k=e+u+c>C+n,v&&!k&&(v=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),eb&&!v&&(c-=l,c=Math.max(b-u,c),c=Math.min(q,c),m&&a.css({top:c+"px"})))):e>F&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(t),null==p&&(a.after(h),"left"!==r&&"right"!==r||h.append(a)),a.trigger("sticky_kit:stick")),m&&w&&(null==k&&(k=e+u+c>C+n),!v&&k)))return v=!0,"static"===g.css("position")&&g.css({position:"relative"}), +a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")},y=function(){x();return l()},H=function(){G=!0;f.off("touchmove",l);f.off("scroll",l);f.off("resize",y);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",H);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});g.position("position","");if(m)return null==p&&("left"!==r&&"right"!==r||a.insertAfter(h),h.remove()),a.removeClass(t)},f.on("touchmove",l),f.on("scroll",l),f.on("resize", +y),b(document.body).on("sticky_kit:recalc",y),a.on("sticky_kit:detach",H),setTimeout(l,0)}};n=0;for(K=this.length;n + + + + + diff --git a/docs/news/index.html b/docs/news/index.html new file mode 100644 index 000000000..15974f5fb --- /dev/null +++ b/docs/news/index.html @@ -0,0 +1,141 @@ + + + + + + + + +All news • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+ +
+ + +
+
+

+styler 0.0-3 (2017-06-15)

+
    +
  • Technical release for creation of pkgdown documentation.
  • +
+
+
+

+styler 0.0-2 (2017-06-15)

+
    +
  • Technical release for creation of pkgdown documentation.
  • +
+
+
+

+styler 0.0-1 (2017-06-15)

+

Initial release, work in progress.

+
    +
  • Create and serialize nested parse data.
  • +
  • Internal support for indention of expressions with parentheses.
  • +
  • Adding and removing spaces around operators on flat parse data.
  • +
+
+
+
+ + + +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/pkgdown.css b/docs/pkgdown.css new file mode 100644 index 000000000..bcc0bd745 --- /dev/null +++ b/docs/pkgdown.css @@ -0,0 +1,158 @@ +/* Sticker footer */ +body > .container { + display: flex; + padding-top: 60px; + min-height: calc(100vh); + flex-direction: column; +} + +body > .container .row { + flex: 1; +} + +footer { + margin-top: 45px; + padding: 35px 0 36px; + border-top: 1px solid #e5e5e5; + color: #666; + display: flex; +} +footer p { + margin-bottom: 0; +} +footer div { + flex: 1; +} +footer .pkgdown { + text-align: right; +} +footer p { + margin-bottom: 0; +} + +img.icon { + float: right; +} + +img { + max-width: 100%; +} + +/* Section anchors ---------------------------------*/ + +a.anchor { + margin-left: -30px; + display:inline-block; + width: 30px; + height: 30px; + visibility: hidden; + + background-image: url(./link.svg); + background-repeat: no-repeat; + background-size: 20px 20px; + background-position: center center; +} + +.hasAnchor:hover a.anchor { + visibility: visible; +} + +@media (max-width: 767px) { + .hasAnchor:hover a.anchor { + visibility: hidden; + } +} + + +/* Fixes for fixed navbar --------------------------*/ + +.contents h1, .contents h2, .contents h3, .contents h4 { + padding-top: 60px; + margin-top: -60px; +} + +/* Static header placement on mobile devices */ +@media (max-width: 767px) { + .navbar-fixed-top { + position: absolute; + } + .navbar { + padding: 0; + } +} + + +/* Sidebar --------------------------*/ + +#sidebar { + margin-top: 30px; +} +#sidebar h2 { + font-size: 1.5em; + margin-top: 1em; +} + +#sidebar h2:first-child { + margin-top: 0; +} + +#sidebar .list-unstyled li { + margin-bottom: 0.5em; +} + +/* Reference index & topics ----------------------------------------------- */ + +.ref-index th {font-weight: normal;} +.ref-index h2 {font-size: 20px;} + +.ref-index td {vertical-align: top;} +.ref-index .alias {width: 40%;} +.ref-index .title {width: 60%;} + +.ref-index .alias {width: 40%;} +.ref-index .title {width: 60%;} + +.ref-arguments th {text-align: right; padding-right: 10px;} +.ref-arguments th, .ref-arguments td {vertical-align: top;} +.ref-arguments .name {width: 20%;} +.ref-arguments .desc {width: 80%;} + +/* Nice scrolling for wide elements --------------------------------------- */ + +table { + display: block; + overflow: auto; +} + +/* Syntax highlighting ---------------------------------------------------- */ + +pre { + word-wrap: normal; + word-break: normal; + border: 1px solid #eee; +} + +pre, code { + background-color: #f8f8f8; + color: #333; +} + +pre img { + background-color: #fff; + display: block; +} + +code a, pre a { + color: #375f84; +} + +.fl {color: #1514b5;} +.fu {color: #000000;} /* function */ +.ch,.st {color: #036a07;} /* string */ +.kw {color: #264D66;} /* keyword */ +.co {color: #888888;} /* comment */ + +.message { color: black; font-weight: bolder;} +.error { color: orange; font-weight: bolder;} +.warning { color: #6A0366; font-weight: bolder;} + diff --git a/docs/pkgdown.js b/docs/pkgdown.js new file mode 100644 index 000000000..c8b38c49d --- /dev/null +++ b/docs/pkgdown.js @@ -0,0 +1,8 @@ +$(function() { + $("#sidebar").stick_in_parent({offset_top: 40}); + $('body').scrollspy({ + target: '#sidebar', + offset: 60 + }); + +}); diff --git a/docs/reference/add_token_terminal.html b/docs/reference/add_token_terminal.html new file mode 100644 index 000000000..306e538c9 --- /dev/null +++ b/docs/reference/add_token_terminal.html @@ -0,0 +1,127 @@ + + + + + + + + +Add information about previous / next token to each terminal — add_token_terminal • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Add information about previous / next token to each terminal

+ + +
add_terminal_token_after(pd_flat)
+
+add_terminal_token_before(pd_flat)
+ +

Arguments

+ + + + + + +
pd_flat

A flat parse table.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/apply_transformers.html b/docs/reference/apply_transformers.html new file mode 100644 index 000000000..bf074a2d8 --- /dev/null +++ b/docs/reference/apply_transformers.html @@ -0,0 +1,135 @@ + + + + + + + + +Apply transformers to a parse table — apply_transformers • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Depending on whether transformers contains functions to modify the +line break information, the column multi_line is updated (after +the line break information is modified) and +the rest of the transformers is applied afterwards, or (if line break +information is not to be modified), all transformers are applied in one +step. The former requires two pre visits and one post visit, the latter +only one pre visit.

+ + +
apply_transformers(pd_nested, transformers)
+ +

Arguments

+ + + + + + + + + + +
pd_nested

A nested parse table.

transformers

A list of named transformer functions

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/character_to_ordered.html b/docs/reference/character_to_ordered.html new file mode 100644 index 000000000..e17da81b6 --- /dev/null +++ b/docs/reference/character_to_ordered.html @@ -0,0 +1,135 @@ + + + + + + + + +Convert a character vector to an ordered factor — character_to_ordered • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Convert a vector to an ordered factor but stop if any of the values in +x does not match the predefined levels in levels.

+ + +
character_to_ordered(x, levels, name = substitute(x))
+ +

Arguments

+ + + + + + + + + + + + + + +
x

A character vector.

levels

A vector with levels.

name

The name of the character vector to be dispayed if the +construction of the factor fails.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/combine_children.html b/docs/reference/combine_children.html new file mode 100644 index 000000000..b32e906cf --- /dev/null +++ b/docs/reference/combine_children.html @@ -0,0 +1,138 @@ + + + + + + + + +Combine child and internal child — combine_children • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

binds two parse tables together and arranges them so that the tokens are in +the correct order.

+ + +
combine_children(child, internal_child)
+ +

Arguments

+ + + + + + + + + + +
child

A parse table or NULL.

internal_child

A parse table or NULL.

+ +

Details

+ +

Essentially, this is a wrapper around dplyr::bind_rows(), but +returns NULL if the result of dplyr::bind_rows() is a data frame with +zero rows.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/compute_indent_indices.html b/docs/reference/compute_indent_indices.html new file mode 100644 index 000000000..78c63ae57 --- /dev/null +++ b/docs/reference/compute_indent_indices.html @@ -0,0 +1,142 @@ + + + + + + + + +Compute the indices that need indention — compute_indent_indices • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Based on token, find the rows in pd that need to be indented.

+ + +
compute_indent_indices(pd, token = "'('", indent_last = FALSE)
+ +

Arguments

+ + + + + + + + + + + + + + +
pd

A parse table.

token

A character vector with tokens.

indent_last

Flag to indicate whether the last token in pd should +be indented or not. See 'Details'.

+ +

Details

+ +

For example when token is a parenthesis, the closing parenthesis does not +need indention, but if token is something else, for example a plus (+), the +last token in pd needs indention.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/compute_parse_data_flat_enhanced.html b/docs/reference/compute_parse_data_flat_enhanced.html new file mode 100644 index 000000000..44c2a46a2 --- /dev/null +++ b/docs/reference/compute_parse_data_flat_enhanced.html @@ -0,0 +1,155 @@ + + + + + + + + +Parse and pre-process character vector — compute_parse_data_flat_enhanced • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

The function obtains detailed parse information for text via +utils::getParseData() and does some minimal pre-processing by calling +enhance_parse_data().

+ + +
compute_parse_data_flat_enhanced(text)
+ +

Arguments

+ + + + + + +
text

A character vector.

+ +

Value

+ +

A pre-processed parse table.

+ +

Details

+ +

Roughly speaking, this is the inverse operation of +serialize_parse_data_flat(), which turns a parse table into a character +vector, since compute_parse_data_flat_enhanced() turns a character vector +into a parse table.

+ +

Details

+ + +

Preprocessing includes

    +
  • removing non-terminal entries.

  • +
  • removing columns id, parent and terminal.

  • +
  • adding a start token.

  • +
  • adding line-break and space information.

  • +
  • removing spaces in comments at the end of the line.

  • +
+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/compute_parse_data_nested.html b/docs/reference/compute_parse_data_nested.html new file mode 100644 index 000000000..e35fbafb7 --- /dev/null +++ b/docs/reference/compute_parse_data_nested.html @@ -0,0 +1,157 @@ + + + + + + + + +Obtain a nested parse table from a character vector — compute_parse_data_nested • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Parses text to a flat parse table and subsequently changes its +representation into a nested parse table with +nest_parse_data().

+ + +
compute_parse_data_nested(text)
+ +

Arguments

+ + + + + + +
text

A character vector to parse.

+ +

Value

+ +

A nested parse table. Apart from the columns provided by +utils::getParseData(), a column "short" with the first five characters of +"text" is added, the nested subtibbles are in column "child". +TODO:

    +
  • Implement enhance_parse_data_nested()

      +
    • Walk tree defined by child, compute whitespace information

    • +
    • Store indention depth in a separate column, unaffected by +inter-token space

    • +
  • +
  • Implement compute_parse_data_nested_with_ws() as +compute_parse_data_nested() + enhance_parse_data_nested()

  • +
  • Implement serialization of nested parse data

  • +
  • Use compute_parse_data_nested_with_ws() instead of +compute_parse_data_flat_enhanced()

  • +
  • Perform all transformations on hierarchical structure

      +
    • Compute text for a sub-element

    • +
  • +
  • Compute indentation

      +
    • Braces

    • +
    • Function calls

    • +
    • Function definitions

    • +
  • +
  • Remove includeText = TRUE

  • +
+ + + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/construct_out.html b/docs/reference/construct_out.html new file mode 100644 index 000000000..147d236d6 --- /dev/null +++ b/docs/reference/construct_out.html @@ -0,0 +1,131 @@ + + + + + + + + +Construct *-out.R from a *-in.R — construct_out • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Multiple *-in.R files can have the same *-out.R file since to create the +*-out.R file, everything after the first dash is replaced by *-out.R.

+ + +
construct_out(in_paths)
+ +

Arguments

+ + + + + + +
in_paths

A character vector that denotes paths to *-in.R files.

+ + +

Examples

+
styler:::construct_out(c("path/to/file/first-in.R", + "path/to/file/first-extended-in.R"))
#> [1] "path/to/file/first-out.R" "path/to/file/first-out.R"
+
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/construct_tree.html b/docs/reference/construct_tree.html new file mode 100644 index 000000000..9222a44e8 --- /dev/null +++ b/docs/reference/construct_tree.html @@ -0,0 +1,129 @@ + + + + + + + + +Construct paths of a tree object given the paths of *-in.R files — construct_tree • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Construct paths of a tree object given the paths of *-in.R files

+ + +
construct_tree(in_paths, suffix = "_tree")
+ +

Arguments

+ + + + + + + + + + +
in_paths

Character vector of *-in.R files.

suffix

Suffix for the tree object.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/create_filler.html b/docs/reference/create_filler.html new file mode 100644 index 000000000..ff706fb68 --- /dev/null +++ b/docs/reference/create_filler.html @@ -0,0 +1,133 @@ + + + + + + + + +Enrich parse table with space and linebreak information — create_filler • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

This function computes difference (as column and line difference) between two +entries in the parse table and adds this information to the table.

+ + +
create_filler(pd_flat)
+ +

Arguments

+ + + + + + +
pd_flat

A parse table.

+ +

Value

+ +

A parse table with two three columns: lag_newlines, newlines and +spaces.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/create_filler_nested.html b/docs/reference/create_filler_nested.html new file mode 100644 index 000000000..92788232b --- /dev/null +++ b/docs/reference/create_filler_nested.html @@ -0,0 +1,138 @@ + + + + + + + + +Enrich nested parse table with space and linebreak information — create_filler_nested • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Uses create_filler() in a recursion add space and line break information +separately on every level of nesting.

+ + +
create_filler_nested(pd_nested)
+ +

Arguments

+ + + + + + +
pd_nested

A nested parse table.

+ +

Value

+ +

A nested parse table with two new columns: newlines and spaces.

+ +

See also

+ +

create_filler()

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/create_node_from_nested.html b/docs/reference/create_node_from_nested.html new file mode 100644 index 000000000..9a51c90bb --- /dev/null +++ b/docs/reference/create_node_from_nested.html @@ -0,0 +1,129 @@ + + + + + + + + +Create node from nested parse data — create_node_from_nested • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Create node from nested parse data

+ + +
create_node_from_nested(pd_nested, parent)
+ +

Arguments

+ + + + + + + + + + +
pd_nested

A nested tibble.

parent

The parent of the node to be created.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/create_node_from_nested_root.html b/docs/reference/create_node_from_nested_root.html new file mode 100644 index 000000000..9a0b44d79 --- /dev/null +++ b/docs/reference/create_node_from_nested_root.html @@ -0,0 +1,142 @@ + + + + + + + + +Convert a nested tibble into a node tree — create_node_from_nested_root • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

This function is convenient to display all nesting levels of a nested tibble +at once.

+ + +
create_node_from_nested_root(pd_nested)
+ +

Arguments

+ + + + + + +
pd_nested

A nested tibble.

+ +

Value

+ +

An object of class "Node" and "R6".

+ + +

Examples

+
library("magrittr")
#> +#> Attaching package: ‘magrittr’
#> The following object is masked from ‘package:styler’: +#> +#> extract
code <- "a <- function(x) { if(x > 1) { 1+1 } else {x} }" +l1 <- styler:::compute_parse_data_nested(code) %>% + styler:::pre_visit(c(styler:::create_filler)) %>% + styler:::create_node_from_nested_root()
#> Warning: replacing previous import ‘scales::viridis_pal’ by ‘viridis::viridis_pal’ when loading ‘DiagrammeR’
+
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/create_tree.html b/docs/reference/create_tree.html new file mode 100644 index 000000000..022aad456 --- /dev/null +++ b/docs/reference/create_tree.html @@ -0,0 +1,131 @@ + + + + + + + + +Create a tree from text — create_tree • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Create a tree representation from a text.

+ + +
create_tree(text)
+ +

Arguments

+ + + + + + +
text

A character vector.

+ +

Value

+ +

A data frame.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/enhance_mapping_special.html b/docs/reference/enhance_mapping_special.html new file mode 100644 index 000000000..38a444f60 --- /dev/null +++ b/docs/reference/enhance_mapping_special.html @@ -0,0 +1,126 @@ + + + + + + + + +Enhance the mapping of text to the token "SPECIAL" — enhance_mapping_special • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Map text corresponding to the token "SPECIAL" to a (more) unique token +description.

+ + +
enhance_mapping_special(pd)
+ +

Arguments

+ + + + + + +
pd

A parse table.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/enhance_parse_data.html b/docs/reference/enhance_parse_data.html new file mode 100644 index 000000000..8d97cbdb5 --- /dev/null +++ b/docs/reference/enhance_parse_data.html @@ -0,0 +1,144 @@ + + + + + + + + +Pre-processing parse data — enhance_parse_data • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Modifies the parse table minimally by applying some pre-processing steps.

+ + +
enhance_parse_data(parse_data)
+ +

Arguments

+ + + + + + +
parse_data

a parse table.

+ +

Value

+ +

a pre-processed parse table.

+ +

Details

+ + +

Preprocessing includes

    +
  • removing non-terminal entries.

  • +
  • removing columns id, parent and terminal.

  • +
  • adding a start token.

  • +
  • adding line-break and space information.

  • +
  • removing spaces in comments at the end of the line.

  • +
+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/flatten_operators.html b/docs/reference/flatten_operators.html new file mode 100644 index 000000000..89efb2c43 --- /dev/null +++ b/docs/reference/flatten_operators.html @@ -0,0 +1,130 @@ + + + + + + + + +Flatten some token in the nested parse table based on operators — flatten_operators • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Certain tokens are not placed optimally in the nested parse data with +compute_parse_data_nested(). For example, the token of arithmetic +operations 1 + 1 + 1 should all be on the same level of nesting since +the indention is the same for all but the first two terminals. Setting the +indention correcly is easier to achieve if they are put on the same level +of nesting.

+ + +
flatten_operators(pd_nested)
+ +

Arguments

+ + + + + + +
pd_nested

A nested parse table to partially flatten.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/get_transformers.html b/docs/reference/get_transformers.html new file mode 100644 index 000000000..a206e84ce --- /dev/null +++ b/docs/reference/get_transformers.html @@ -0,0 +1,139 @@ + + + + + + + + +Get the transformer functions for styling — get_transformers • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Get the transformer functions for styling

+ + +
get_transformers(flat = FALSE, ...)
+ +

Arguments

+ + + + + + + + + + +
flat

Whether the transformer functions for flat or nested styling +should be returned.

...

Parameters passed to

+ +

Value

+ +

A list of transformer functions that operate on flat parse tables.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/get_transformers_flat.html b/docs/reference/get_transformers_flat.html new file mode 100644 index 000000000..a1aca695f --- /dev/null +++ b/docs/reference/get_transformers_flat.html @@ -0,0 +1,144 @@ + + + + + + + + +Get the transformer functions for flat styling — get_transformers_flat • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Get the transformer functions for flat styling

+ + +
get_transformers_flat(strict = TRUE, start_comments_with_one_space = FALSE)
+ +

Arguments

+ + + + + + + + + + +
strict

A logical value indicating whether a set of strict +or not so strict transformer functions should be returned.

start_comments_with_one_space

Whether or not comments should start +with only one space (see start_comments_with_space()).

+ +

Value

+ +

A list of transformer functions that operate on flat parse +tables.

+ +

See also

+ +

Other obtain transformers: get_transformers_nested

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/get_transformers_nested.html b/docs/reference/get_transformers_nested.html new file mode 100644 index 000000000..3917bdbdd --- /dev/null +++ b/docs/reference/get_transformers_nested.html @@ -0,0 +1,165 @@ + + + + + + + + +Get the transformer functions for nested styling — get_transformers_nested • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Similar to get_transformers_flat(), but additionally, returns some +functions needed due the fact that styling is done in a nested way.

+ + +
get_transformers_nested(scope = "tokens", strict = TRUE, indent_by = 2,
+  start_comments_with_one_space = FALSE)
+ +

Arguments

+ + + + + + + + + + + + + + + + + + +
scope

The extent of manipulation. Can range from "none" (least +invasive) to "token" (most invasive). See 'Details'. This argument is a +vector of length one.

strict

A logical value indicating whether a set of strict +or not so strict transformer functions should be returned.

indent_by

How many spaces of indention should be inserted after +operators such as '('.

start_comments_with_one_space

Whether or not comments should start +with only one space (see start_comments_with_space()).

+ +

Details

+ +

The following options for scope are available.

    +
  • "none": Performs no transformation at all.

  • +
  • "spaces": Manipulates spacing between token on the same line.

  • +
  • "line_breaks": In addition to "spaces", this option also manipulates +line breaks.

  • +
  • "tokens": In addition to "line_breaks", this option also manipulates +tokens.

  • +
+

As it becomes clear from this description, more invasive operations can only +be performed if all less invasive operations are performed too.

+ +

See also

+ +

Other obtain transformers: get_transformers_flat

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/index.html b/docs/reference/index.html new file mode 100644 index 000000000..6ed65586d --- /dev/null +++ b/docs/reference/index.html @@ -0,0 +1,467 @@ + + + + + + + + +Function reference • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

All functions

+

+
+

add_terminal_token_after add_terminal_token_before

+

Add information about previous / next token to each terminal

+

apply_transformers

+

Apply transformers to a parse table

+

character_to_ordered

+

Convert a character vector to an ordered factor

+

combine_children

+

Combine child and internal child

+

compute_indent_indices

+

Compute the indices that need indention

+

compute_parse_data_flat_enhanced

+

Parse and pre-process character vector

+

compute_parse_data_nested

+

Obtain a nested parse table from a character vector

+

construct_out

+

Construct *-out.R from a *-in.R

+

construct_tree

+

Construct paths of a tree object given the paths of *-in.R files

+

create_filler

+

Enrich parse table with space and linebreak information

+

create_node_from_nested_root

+

Convert a nested tibble into a node tree

+

create_node_from_nested

+

Create node from nested parse data

+

create_tree

+

Create a tree from text

+

enhance_mapping_special

+

Enhance the mapping of text to the token "SPECIAL"

+

enhance_parse_data

+

Pre-processing parse data

+

flatten_operators

+

Flatten some token in the nested parse table based on operators

+

get_transformers_flat

+

Get the transformer functions for flat styling

+

get_transformers_nested

+

Get the transformer functions for nested styling

+

get_transformers

+

Get the transformer functions for styling

+

lookup_new_special

+

lookup which new tokens were created from "SPECIAL"

+

make_transformer_flat

+

A Closure to return transformer function

+

make_transformer_nested

+

Closure to return transformer function

+

make_transformer

+

Closure to return a transformer function

+

needs_indention

+

Check whether indention is needed

+

nest_parse_data

+

Nest a flat parse table

+

newlines_and_spaces

+

concentrate newlines an spaces in a string

+

parse_transform_serialize

+

Parse, transform and serialize text

+

prettify_one

+

Prettify one R file

+

rep_char

+

Repeat elements of a character vector times times and collapse it

+

serialize_parse_data_flat

+

Serialize Flat Parse Data

+

serialize_parse_data_nested_helper

+

Serialize a nested parse table

+

serialize_parse_data_nested

+

Serialize a nested parse table

+

set_multi_line

+

Set the multi-line column

+

set_space_between_levels

+

Set space between levels of nesting

+

set_spaces

+

Helper for setting spaces

+

set_unindention_child

+

Unindent a chlid if necessary

+

start_comments_with_space

+

Start comments with a space

+

start_on_line

+

Get the start right

+

strip_eol_spaces

+

Strip EOL spaces

+

style_active_file

+

Style the active file

+

style_dir

+

Prettify arbitrary R code

+

style_file

+

Style a file

+

style_pkg

+

Prettify R source code

+

style_text

+

Style a string

+

+

Non-invasive pretty printing of R code

+

test_collection

+

Run a collection of tests

+

style_indent_round style_empty style_indent_curly style_indent_curly_round style_op

+

Transforming test input with a transformer function

+

token_is_multi_line

+

Check whether a parse table is a multi-line token

+

tokenize

+

Obtain token table from text

+

transform_and_check

+

Transform a file an check the result

+

transform_files

+

Transform files with transformer functions

+

unindent_child

+

Unindent a child

+

indent_round indent_curly indent_op indent_assign indent_without_paren

+

Update indention information of parse data

+

verify_roundtrip

+

Verify parse data modifications

+

visit_one

+

Transform a flat parse table with a list of transformers

+

pre_visit post_visit

+

Visit'em all

+
+
+ + +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/lookup_new_special.html b/docs/reference/lookup_new_special.html new file mode 100644 index 000000000..0a8844096 --- /dev/null +++ b/docs/reference/lookup_new_special.html @@ -0,0 +1,125 @@ + + + + + + + + +lookup which new tokens were created from "SPECIAL" — lookup_new_special • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

lookup which new tokens were created from "SPECIAL"

+ + +
lookup_new_special(regex = NA)
+ +

Arguments

+ + + + + + +
regex

A regular expression pattern to search for.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/make_transformer.html b/docs/reference/make_transformer.html new file mode 100644 index 000000000..c95db3d09 --- /dev/null +++ b/docs/reference/make_transformer.html @@ -0,0 +1,140 @@ + + + + + + + + +Closure to return a transformer function — make_transformer • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

This function takes a list of transformer functions as input and +returns a function that can be applied to character strings +that should be transformed.

+ + +
make_transformer(transformers, flat)
+ +

Arguments

+ + + + + + + + + + +
transformers

A list of transformer functions that operate on flat +parse tables.

flat

Whether to do the styling with a flat approach or with a nested +approach.

+ +

See also

+ +

Other make transformers: make_transformer_flat, + make_transformer_nested

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/make_transformer_flat.html b/docs/reference/make_transformer_flat.html new file mode 100644 index 000000000..1ed7e6086 --- /dev/null +++ b/docs/reference/make_transformer_flat.html @@ -0,0 +1,134 @@ + + + + + + + + +A Closure to return transformer function — make_transformer_flat • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Returns a closure that turns text into a flat parse table and applies +transformers on it.

+ + +
make_transformer_flat(transformers)
+ +

Arguments

+ + + + + + +
transformers

A list of transformer functions that operate on flat +parse tables.

+ +

See also

+ +

Other make transformers: make_transformer_nested, + make_transformer

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/make_transformer_nested.html b/docs/reference/make_transformer_nested.html new file mode 100644 index 000000000..93d1bfad1 --- /dev/null +++ b/docs/reference/make_transformer_nested.html @@ -0,0 +1,134 @@ + + + + + + + + +Closure to return transformer function — make_transformer_nested • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Returns a closure that turns text into a nested parse table and applies +transformers on it.

+ + +
make_transformer_nested(transformers)
+ +

Arguments

+ + + + + + +
transformers

A list of transformer functions that operate on flat +parse tables.

+ +

See also

+ +

Other make transformers: make_transformer_flat, + make_transformer

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/needs_indention.html b/docs/reference/needs_indention.html new file mode 100644 index 000000000..b2c15a96c --- /dev/null +++ b/docs/reference/needs_indention.html @@ -0,0 +1,142 @@ + + + + + + + + +Check whether indention is needed — needs_indention • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Check whether indention is needed

+ + +
needs_indention(pd, opening)
+ +

Arguments

+ + + + + + + + + + +
pd

A parse table.

opening

the index of the opening parse table. Since always computed +before this function is called, it is included as an argument so it does +not have to be recomputed.

+ +

Value

+ +

returns TRUE if indention is needed, FALSE otherwise. Indention +is needed if and only if: +* the opening token is not NA. +* if there is a multi-line token before the first line break. + +TRUE if indention is needed, FALSE otherwise.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/nest_parse_data.html b/docs/reference/nest_parse_data.html new file mode 100644 index 000000000..7d86f654e --- /dev/null +++ b/docs/reference/nest_parse_data.html @@ -0,0 +1,142 @@ + + + + + + + + +Nest a flat parse table — nest_parse_data • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

nest_parse_data groups pd_flat into a parse table with tokens that are +a parent to other tokens (called internal) and such that are not (called +child). Then, the token in child are joined to their parents in internal +and all token information of the children is nested into a column "child". +This is done recursively until we are only left with a nested tibble that +contains one row: The nested parse table.

+ + +
nest_parse_data(pd_flat)
+ +

Arguments

+ + + + + + +
pd_flat

A flat parse table including both terminals and non-terminals.

+ +

Value

+ +

A nested parse table.

+ +

See also

+ +

compute_parse_data_nested()

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/newlines_and_spaces.html b/docs/reference/newlines_and_spaces.html new file mode 100644 index 000000000..08a3093c0 --- /dev/null +++ b/docs/reference/newlines_and_spaces.html @@ -0,0 +1,136 @@ + + + + + + + + +concentrate newlines an spaces in a string — newlines_and_spaces • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

concentrate newlines an spaces in a string

+ + +
newlines_and_spaces(newlines, spaces)
+ +

Arguments

+ + + + + + + + + + +
newlines

Scalar indicating how many newlines ("\ n") should returned.

spaces

Scalar indicating how many spaces should be appended to the +newlines.

+ +

Value

+ +

A string.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/parse_transform_serialize.html b/docs/reference/parse_transform_serialize.html new file mode 100644 index 000000000..c2f07147c --- /dev/null +++ b/docs/reference/parse_transform_serialize.html @@ -0,0 +1,129 @@ + + + + + + + + +Parse, transform and serialize text — parse_transform_serialize • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Wrapper function for the common three operations.

+ + +
parse_transform_serialize(text, transformers)
+ +

Arguments

+ + + + + + + + + + +
text

A character vector to parse.

transformers

A list of named transformer functions

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/prettify_any.html b/docs/reference/prettify_any.html new file mode 100644 index 000000000..9ac2a89ac --- /dev/null +++ b/docs/reference/prettify_any.html @@ -0,0 +1,135 @@ + + + + + + + + +Prettify R code in current working directory — prettify_any • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

This is a helper function for style_dir.

+ + +
prettify_any(transformers, recursive, flat)
+ +

Arguments

+ + + + + + + + + + + + + + +
transformers

A list with functions to be applied to the parsed data.

recursive

A logical value indicating whether or not files in subdirectories +should be styled as well.

flat

Whether to do the styling with a flat approach or with a nested +approach.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/prettify_one.html b/docs/reference/prettify_one.html new file mode 100644 index 000000000..720053bef --- /dev/null +++ b/docs/reference/prettify_one.html @@ -0,0 +1,134 @@ + + + + + + + + +Prettify one R file — prettify_one • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

This is a helper function for style_dir.

+ + +
prettify_one(transformers, flat, path)
+ +

Arguments

+ + + + + + + + + + + + + + +
transformers

A list with functions to be applied to the parsed data.

flat

Whether to do the styling with a flat approach or with a nested +approach.

path

The path to a file that should be styled.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/rep_char.html b/docs/reference/rep_char.html new file mode 100644 index 000000000..f14fa2c6a --- /dev/null +++ b/docs/reference/rep_char.html @@ -0,0 +1,135 @@ + + + + + + + + +Repeat elements of a character vector <code>times</code> times and collapse it — rep_char • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Repeat elements of a character vector times times and collapse it

+ + +
rep_char(char, times)
+ +

Arguments

+ + + + + + + + + + +
char

A character vector.

times

an integer giving the number of repetitions.

+ +

Value

+ +

A character vector.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/serialize_parse_data_flat.html b/docs/reference/serialize_parse_data_flat.html new file mode 100644 index 000000000..3c2b3617b --- /dev/null +++ b/docs/reference/serialize_parse_data_flat.html @@ -0,0 +1,137 @@ + + + + + + + + +Serialize Flat Parse Data — serialize_parse_data_flat • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Collapses a parse table into character vector representation.

+ + +
serialize_parse_data_flat(pd_flat)
+ +

Arguments

+ + + + + + +
pd_flat

A parse table.

+ +

Details

+ +

The function essentially collapses the column text of pd_flat +while taking into account space and linebreak information from the columns +newlines and spaces. +Roughly speaking, this is the inverse operation of +compute_parse_data_flat_enhanced(), which turns a character vector into a +parse table, since serialize_parse_data_flat() turns a parse table back +into a character vector.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/serialize_parse_data_nested.html b/docs/reference/serialize_parse_data_nested.html new file mode 100644 index 000000000..6875dd348 --- /dev/null +++ b/docs/reference/serialize_parse_data_nested.html @@ -0,0 +1,132 @@ + + + + + + + + +Serialize a nested parse table — serialize_parse_data_nested • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Collapses a nested parse table into its character vector representation.

+ + +
serialize_parse_data_nested(pd_nested)
+ +

Arguments

+ + + + + + +
pd_nested

A nested parse table with line break, spaces and indention +information.

+ +

Value

+ +

A character string.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/serialize_parse_data_nested_helper.html b/docs/reference/serialize_parse_data_nested_helper.html new file mode 100644 index 000000000..15c5b320d --- /dev/null +++ b/docs/reference/serialize_parse_data_nested_helper.html @@ -0,0 +1,137 @@ + + + + + + + + +Serialize a nested parse table — serialize_parse_data_nested_helper • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Helper function that recursively extracts terminals from a nested tibble.

+ + +
serialize_parse_data_nested_helper(pd_nested, pass_indent)
+ +

Arguments

+ + + + + + + + + + +
pd_nested

A nested parse table.

pass_indent

Level of indention of a token.

+ +

Value

+ +

A character vector with all terminal tokens in pd_nested plus +the appropriate amount of white spaces and line breaks are inserted between +them.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/set_multi_line.html b/docs/reference/set_multi_line.html new file mode 100644 index 000000000..d572f0a68 --- /dev/null +++ b/docs/reference/set_multi_line.html @@ -0,0 +1,126 @@ + + + + + + + + +Set the multi-line column — set_multi_line • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Sets the column multi_line in pd by checking row-wise whether any child +of a token is a multi-line token.

+ + +
set_multi_line(pd)
+ +

Arguments

+ + + + + + +
pd

A parse table.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/set_space_between_levels.html b/docs/reference/set_space_between_levels.html new file mode 100644 index 000000000..96ceab3fd --- /dev/null +++ b/docs/reference/set_space_between_levels.html @@ -0,0 +1,129 @@ + + + + + + + + +Set space between levels of nesting — set_space_between_levels • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

With the nested approach, certain rules do not have an effect anymore because +of the nature of the nested structure. Setting spacing before curly +brackets in for / if / while statements and function declarations will be +such a case since a curly bracket is always at the first position in a +parse table, so spacing cannot be set after the previous token.

+ + +
set_space_between_levels(pd_flat)
+ +

Arguments

+ + + + + + +
pd_flat

A flat parse table.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/set_spaces.html b/docs/reference/set_spaces.html new file mode 100644 index 000000000..015af3261 --- /dev/null +++ b/docs/reference/set_spaces.html @@ -0,0 +1,139 @@ + + + + + + + + +Helper for setting spaces — set_spaces • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Helper for setting spaces

+ + +
set_spaces(spaces_after_prefix, force_one)
+ +

Arguments

+ + + + + + + + + + +
spaces_after_prefix

An integer vector with the number of spaces +after the prefix.

force_one

Whether spaces_after_prefix should be set to one in all +cases.

+ +

Value

+ +

An integer vector of length spaces_after_prefix, which is either +one (if force_one = TRUE) or space_after_prefix with all values +below one set to one.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/set_unindention_child.html b/docs/reference/set_unindention_child.html new file mode 100644 index 000000000..a95015d33 --- /dev/null +++ b/docs/reference/set_unindention_child.html @@ -0,0 +1,134 @@ + + + + + + + + +Unindent a chlid if necessary — set_unindention_child • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

check whether any of the children of pd has token on the same line as +the closing token of pd. If so, unindent that token.

+ + +
set_unindention_child(pd, token = "')'", unindent_by)
+ +

Arguments

+ + + + + + + + + + + + + + +
pd

A parse table.

token

The token the unindention should be based on.

unindent_by

By how many spaces one level of indention is reversed.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/start_comments_with_space.html b/docs/reference/start_comments_with_space.html new file mode 100644 index 000000000..8ca4e4e30 --- /dev/null +++ b/docs/reference/start_comments_with_space.html @@ -0,0 +1,132 @@ + + + + + + + + +Start comments with a space — start_comments_with_space • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Forces comments to start with a space, that is, after the regular expression +"^#+'*", at least one space must follow. Multiple spaces may be legit for +indention in some situations.

+ + +
start_comments_with_space(pd, force_one = FALSE)
+ +

Arguments

+ + + + + + + + + + +
pd

A parse table.

force_one

Wheter or not to force one space or allow multiple spaces +after the regex "^#+'*".

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/start_on_line.html b/docs/reference/start_on_line.html new file mode 100644 index 000000000..5375538ba --- /dev/null +++ b/docs/reference/start_on_line.html @@ -0,0 +1,131 @@ + + + + + + + + +Get the start right — start_on_line • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

On what line does the first token occur?

+ + +
start_on_line(pd)
+ +

Arguments

+ + + + + + +
pd

A parse table.

+ +

Value

+ +

The line number on which the first token occurs.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/strip_eol_spaces.html b/docs/reference/strip_eol_spaces.html new file mode 100644 index 000000000..da1622bc7 --- /dev/null +++ b/docs/reference/strip_eol_spaces.html @@ -0,0 +1,131 @@ + + + + + + + + +Strip EOL spaces — strip_eol_spaces • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Remove end-of-line spaces.

+ + +
strip_eol_spaces(pd_flat)
+ +

Arguments

+ + + + + + +
pd_flat

A flat parse table.

+ +

Value

+ +

A nested parse table.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/strip_eol_spaces_nested.html b/docs/reference/strip_eol_spaces_nested.html new file mode 100644 index 000000000..0f133af59 --- /dev/null +++ b/docs/reference/strip_eol_spaces_nested.html @@ -0,0 +1,131 @@ + + + + + + + + +Strip EOL spaces — strip_eol_spaces_nested • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Remove end-of-line spaces.

+ + +
strip_eol_spaces_nested(pd_nested)
+ +

Arguments

+ + + + + + +
pd_nested

A nested parse table.

+ +

Value

+ +

A nested parse table.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/style_active_file.html b/docs/reference/style_active_file.html new file mode 100644 index 000000000..816155d69 --- /dev/null +++ b/docs/reference/style_active_file.html @@ -0,0 +1,115 @@ + + + + + + + + +Style the active file — style_active_file • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Helper function fot RStudio Add-in.

+ + +
style_active_file()
+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/style_dir.html b/docs/reference/style_dir.html new file mode 100644 index 000000000..1e06d2a98 --- /dev/null +++ b/docs/reference/style_dir.html @@ -0,0 +1,148 @@ + + + + + + + + +Prettify arbitrary R code — style_dir • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Performs various substitutions in all .R files in a directory. +Carefully examine the results after running this function!

+ + +
style_dir(path = ".", flat = FALSE, recursive = TRUE,
+  transformers = get_transformers(flat = flat))
+ +

Arguments

+ + + + + + + + + + + + + + + + + + +
path

Path to a directory with files to transform.

flat

Whether to do the styling with a flat approach or with a nested +approach.

recursive

A logical value indicating whether or not files in subdirectories +of path should be styled as well.

transformers

A list with functions to be applied to the parsed data.

+ +

See also

+ +

Other stylers: style_file, + style_pkg, style_text

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/style_file.html b/docs/reference/style_file.html new file mode 100644 index 000000000..55d13bd46 --- /dev/null +++ b/docs/reference/style_file.html @@ -0,0 +1,142 @@ + + + + + + + + +Style a file — style_file • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Performs various substitutions in the .R file specified. +Carefully examine the results after running this function!

+ + +
style_file(path, flat = FALSE, transformers = get_transformers(flat = flat))
+ +

Arguments

+ + + + + + + + + + + + + + +
path

A path to a file to style.

flat

Whether to do the styling with a flat approach or with a nested +approach.

transformers

A list with functions to be applied to the parsed data.

+ +

See also

+ +

Other stylers: style_dir, + style_pkg, style_text

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/style_pkg.html b/docs/reference/style_pkg.html new file mode 100644 index 000000000..c1c36d24b --- /dev/null +++ b/docs/reference/style_pkg.html @@ -0,0 +1,144 @@ + + + + + + + + +Prettify R source code — style_pkg • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Performs various substitutions in all .R files in a package +(code and tests). +Carefully examine the results after running this function!

+ + +
style_pkg(pkg = ".", flat = FALSE, transformers = get_transformers(flat =
+  flat))
+ +

Arguments

+ + + + + + + + + + + + + + +
pkg

Path to a (subdirectory of an) R package

flat

Whether to do the styling with a flat approach or with a nested +approach.

transformers

A list with functions to be applied to the parsed data.

+ +

See also

+ +

Other stylers: style_dir, + style_file, style_text

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/style_src.html b/docs/reference/style_src.html new file mode 100644 index 000000000..9d8ea7ce0 --- /dev/null +++ b/docs/reference/style_src.html @@ -0,0 +1,136 @@ + + + + + + + + +Prettify arbitrary R code — style_src • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Performs various substitutions in all .R files in a directory. +Carefully examine the results after running this function!

+ + +
style_src(path = ".", transformers = get_transformers(), recursive = TRUE)
+ +

Arguments

+ + + + + + + + + + + + + + +
path

Path to a directory with files to transform.

transformers

A list of transformer functions to be applied to the +files in path.

recursive

A logical value indicating whether or not files in subdirectories +of path should be styled as well.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/style_text.html b/docs/reference/style_text.html new file mode 100644 index 000000000..b08328a92 --- /dev/null +++ b/docs/reference/style_text.html @@ -0,0 +1,141 @@ + + + + + + + + +Style a string — style_text • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Styles a character vector

+ + +
style_text(text, flat = FALSE, transformers = get_transformers(flat = flat))
+ +

Arguments

+ + + + + + + + + + + + + + +
text

A character vector with text to style.

flat

Whether to do the styling with a flat approach or with a nested +approach.

transformers

A list with functions to be applied to the parsed data.

+ +

See also

+ +

Other stylers: style_dir, + style_file, style_pkg

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/styler-package.html b/docs/reference/styler-package.html new file mode 100644 index 000000000..ff139fb1b --- /dev/null +++ b/docs/reference/styler-package.html @@ -0,0 +1,130 @@ + + + + + + + + +Non-invasive pretty printing of R code — styler-package • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

styler allows you to format .R files, packages or entire R source trees +according to a style guide. See the INDEX for more information.

+ + + +

See also

+ +

Useful links:

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/test_collection.html b/docs/reference/test_collection.html new file mode 100644 index 000000000..f544857a4 --- /dev/null +++ b/docs/reference/test_collection.html @@ -0,0 +1,167 @@ + + + + + + + + +Run a collection of tests — test_collection • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Run transformations on all *-in.R files in a test directory and compare them +with their *-out.R counterpart.

+ + +
test_collection(test, sub_test = NULL, write_back = TRUE,
+  write_tree = TRUE, transformer, ...)
+ +

Arguments

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
test

The test to run. It corresponds to a folder name in +tests/testthat.

sub_test

A regex pattern to further reduce the amount of test files +to be tested in the test. sub_test must match the beginning of file +names in tests/testthat. NULL matches all files.

write_back

Whether the results of the transformation should be written +to the output file.

write_tree

Whether or not the tree structure of the test should be +computed and written to a file.

transformer

A function to apply to the content of in_item.

...

Parameters passed to transformer function.

+ +

Details

+ +

Each file name that matches test and sub_test and ends with +"-in.R" is considered as an input to test. Its counterpart, +the reference to compare it against is the *-out.R file. It is constructed +by taking the substring of the *-in.R file before the +first dash and adding -out.R. This allows for multiple in.R files to +share one out.R file. You could have one_line-out.R as the reference to +compare one_line-random-something-stuff-in.R and +one_line-random-but-not-so-much-in.R.

+

This also implies that -out.R files cannot have more than one dash in +their name, i.e. just the one before out.R.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/test_transformer.html b/docs/reference/test_transformer.html new file mode 100644 index 000000000..d00069840 --- /dev/null +++ b/docs/reference/test_transformer.html @@ -0,0 +1,158 @@ + + + + + + + + +Transforming test input with a transformer function — test_transformer • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

These functions can be used as inputs for test_collection() and +transform_and_check().

+ + +
style_indent_round(text)
+
+style_empty(text)
+
+style_indent_curly(text)
+
+style_indent_curly_round(text)
+
+style_op(text)
+ +

Arguments

+ + + + + + +
text

A character vector to transform.

+ +

Details

+ +

As inputs for test_collection(), we can also use top-level functions such +as style_text().

+ +

Functions

+ +
    +
  • style_indent_round: Transformations for indention based on round +brackets.

  • +
  • style_empty: Nest and unnest text without applying any +transformations but remove EOL spaces and indention due to the way the +serialization is set up.

  • +
  • style_indent_curly: Transformations for indention based on curly +brackets only.

  • +
  • style_indent_curly_round: Transformations for indention based on curly +brackets and round brackets.

  • +
  • style_op: Transformations for indention based on operators

  • +
+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/token_is_multi_line.html b/docs/reference/token_is_multi_line.html new file mode 100644 index 000000000..e11622fa0 --- /dev/null +++ b/docs/reference/token_is_multi_line.html @@ -0,0 +1,134 @@ + + + + + + + + +Check whether a parse table is a multi-line token — token_is_multi_line • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

A token is a multi-line expression if and only if:

+ + +
token_is_multi_line(pd)
+ +

Arguments

+ + + + + + +
pd

A parse table.

+ +

Details

+ +
    +
  • it contains a line break.

  • +
  • it has at least one child that is a multi-line expression itself.

  • +
+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/tokenize.html b/docs/reference/tokenize.html new file mode 100644 index 000000000..b4f9ebf7b --- /dev/null +++ b/docs/reference/tokenize.html @@ -0,0 +1,131 @@ + + + + + + + + +Obtain token table from text — tokenize • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

utils::getParseData() is used to obtain a flat parse table from text.

+ + +
tokenize(text)
+ +

Arguments

+ + + + + + +
text

A character vector.

+ +

Value

+ +

A flat parse table

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/transform_and_check.html b/docs/reference/transform_and_check.html new file mode 100644 index 000000000..e542b3db3 --- /dev/null +++ b/docs/reference/transform_and_check.html @@ -0,0 +1,161 @@ + + + + + + + + +Transform a file an check the result — transform_and_check • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Transform an file and check whether it is identical to a reference.

+ + +
transform_and_check(in_item, out_item, in_name = in_item,
+  out_name = out_item, transformer, write_back, write_tree = FALSE,
+  out_tree = "_tree", ...)
+ +

Arguments

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
in_item

An path to an file to transform.

out_item

The path to a file that contains the expected result.

in_name

The label of the in_item, defaults to in_item.

out_name

The label of the out_item, defaults to out_item.

transformer

A function to apply to the content of in_item.

write_back

Whether the results of the transformation should be written +to the output file.

write_tree

Whether or not the tree structure of the test should be +computed and written to a file.

out_tree

Name of tree file if written out.

...

Parameters passed to transformer function.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/transform_files.html b/docs/reference/transform_files.html new file mode 100644 index 000000000..eaee03815 --- /dev/null +++ b/docs/reference/transform_files.html @@ -0,0 +1,145 @@ + + + + + + + + +Transform files with transformer functions — transform_files • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

transform_files applies transformations to file contents and writes back +the result.

+ + +
transform_files(files, transformers, flat)
+ +

Arguments

+ + + + + + + + + + + + + + +
files

A character vector with paths to the file that should be +transformed.

transformers

A list of transformer functions that operate on flat +parse tables.

flat

Whether to do the styling with a flat approach or with a nested +approach.

+ +

Value

+ +

A logical value that indicates whether or not any file was changed is +returned invisibly. If files were changed, the user is informed to +carefully inspect the changes via a message sent to the console.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/unindent_child.html b/docs/reference/unindent_child.html new file mode 100644 index 000000000..51f8c572e --- /dev/null +++ b/docs/reference/unindent_child.html @@ -0,0 +1,133 @@ + + + + + + + + +Unindent a child — unindent_child • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Unindent a child

+ + +
unindent_child(pd, token = c("')'", "'}'"), unindent_by = 2)
+ +

Arguments

+ + + + + + + + + + + + + + +
pd

A parse table.

token

The token the unindention should be based on.

unindent_by

By how many spaces one level of indention is reversed.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/update_indention.html b/docs/reference/update_indention.html new file mode 100644 index 000000000..458deae79 --- /dev/null +++ b/docs/reference/update_indention.html @@ -0,0 +1,155 @@ + + + + + + + + +Update indention information of parse data — update_indention • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Update indention information of parse data

+ + +
indent_round(pd, indent_by)
+
+indent_curly(pd, indent_by)
+
+indent_op(pd, indent_by, token = c(math_token, "SPECIAL-PIPE"))
+
+indent_assign(pd, indent_by, token = c("LEFT_ASSIGN",
+  "\n                                                   EQ_ASSIGN"))
+
+indent_without_paren(pd, indent_by = 2)
+ +

Arguments

+ + + + + + + + + + + + + + +
pd

A nested or flat parse table that is already enhanced with +line break and space information via create_filler().

indent_by

How many spaces should be added after the token of interest.

token

The token the indention should be based on.

+ +

Functions

+ +
    +
  • indent_round: Inserts indetion based on round brackets.

  • +
  • indent_assign: Same as indent_op, but only indents one token +after token, not all remaining.

  • +
  • indent_without_paren: Is used to indent if / while / for statements +that do not have curly brackets.

  • +
+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/update_indention_nested.html b/docs/reference/update_indention_nested.html new file mode 100644 index 000000000..b98a0c7c3 --- /dev/null +++ b/docs/reference/update_indention_nested.html @@ -0,0 +1,127 @@ + + + + + + + + +Update indention information of nested parse data — update_indention_nested • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

These functions apply the update functions of the same name but without +suffix nested to each level of nesting of the nested parse table.

+ + +
indent_round_nested(pd)
+ +

Arguments

+ + + + + + +
pd

A nested parse table that is already enhanced with +line break and space information via create_filler_nested.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/verify_roundtrip.html b/docs/reference/verify_roundtrip.html new file mode 100644 index 000000000..f57330ed7 --- /dev/null +++ b/docs/reference/verify_roundtrip.html @@ -0,0 +1,144 @@ + + + + + + + + +Verify parse data modifications — verify_roundtrip • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Check whether serializing the parse data results in the same +number of lines as the initial data that should be styled.

+ + +
verify_roundtrip(pd_flat, text)
+ +

Arguments

+ + + + + + + + + + +
pd_flat

A parse table.

text

A character vector with the initial text to compare against.

+ +

Value

+ +

If the verification is successful, pd is returned, with empty +lines at the end of text stripped. +Otherwise, an error is thrown.

+ +

See also

+ +

serialize_parse_data_flat()

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/visit.html b/docs/reference/visit.html new file mode 100644 index 000000000..53a279f31 --- /dev/null +++ b/docs/reference/visit.html @@ -0,0 +1,142 @@ + + + + + + + + +Visit'em all — visit • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Apply a list of functions to each level in a nested parse table. +pre_visit() applies funs before it preceeds to the children, +(that is, starts from the outermost level of nesting progressing +to the innermost level), post_visit() preceeds to its children +before applying the functions (meaning it first applies the functions +to the innermost level of nesting first and then going outwards).

+ + +
pre_visit(pd_nested, funs)
+
+post_visit(pd_nested, funs)
+ +

Arguments

+ + + + + + + + + + +
pd_nested

A nested parse table.

funs

A list of transformer functions.

+ +

See also

+ +

Other visitors: visit_one

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/docs/reference/visit_one.html b/docs/reference/visit_one.html new file mode 100644 index 000000000..921d7234b --- /dev/null +++ b/docs/reference/visit_one.html @@ -0,0 +1,136 @@ + + + + + + + + +Transform a flat parse table with a list of transformers — visit_one • styler + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + + +

Uses purrr::reduce() to apply each function of funs sequentially to +pd_flat.

+ + +
visit_one(pd_flat, funs)
+ +

Arguments

+ + + + + + + + + + +
pd_flat

A flat parse table.

funs

A list of transformer functions.

+ +

See also

+ +

Other visitors: visit

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown.

+
+ +
+
+ + + diff --git a/log4j.spark.log b/log4j.spark.log new file mode 100644 index 000000000..fe352926d --- /dev/null +++ b/log4j.spark.log @@ -0,0 +1,154 @@ +17/06/23 14:57:11 INFO SparkContext: Running Spark version 1.6.2 +17/06/23 14:57:11 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable +17/06/23 14:57:11 INFO SecurityManager: Changing view acls to: muelleki +17/06/23 14:57:11 INFO SecurityManager: Changing modify acls to: muelleki +17/06/23 14:57:11 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users with view permissions: Set(muelleki); users with modify permissions: Set(muelleki) +17/06/23 14:57:11 INFO Utils: Successfully started service 'sparkDriver' on port 34287. +17/06/23 14:57:12 INFO Slf4jLogger: Slf4jLogger started +17/06/23 14:57:12 INFO Remoting: Starting remoting +17/06/23 14:57:12 INFO Remoting: Remoting started; listening on addresses :[akka.tcp://sparkDriverActorSystem@127.0.0.1:40565] +17/06/23 14:57:12 INFO Utils: Successfully started service 'sparkDriverActorSystem' on port 40565. +17/06/23 14:57:12 INFO SparkEnv: Registering MapOutputTracker +17/06/23 14:57:12 INFO SparkEnv: Registering BlockManagerMaster +17/06/23 14:57:12 INFO DiskBlockManager: Created local directory at /tmp/blockmgr-eda582b3-34b6-475e-a42a-083b8a9dcffd +17/06/23 14:57:12 INFO MemoryStore: MemoryStore started with capacity 511.1 MB +17/06/23 14:57:12 INFO SparkEnv: Registering OutputCommitCoordinator +17/06/23 14:57:12 INFO Utils: Successfully started service 'SparkUI' on port 4040. +17/06/23 14:57:12 INFO SparkUI: Started SparkUI at http://127.0.0.1:4040 +17/06/23 14:57:12 INFO HttpFileServer: HTTP File server directory is /tmp/spark-4f8a42c0-4e89-4860-bc01-893ad3442212/httpd-7d9ae7e3-2484-4c55-b7f5-07d25d13cbea +17/06/23 14:57:12 INFO HttpServer: Starting HTTP Server +17/06/23 14:57:12 INFO Utils: Successfully started service 'HTTP file server' on port 39741. +17/06/23 14:57:12 INFO SparkContext: Added JAR file:/home/muelleki/R/x86_64-pc-linux-gnu-library/3.4/sparklyr/java/spark-csv_2.11-1.3.0.jar at http://127.0.0.1:39741/jars/spark-csv_2.11-1.3.0.jar with timestamp 1498222632410 +17/06/23 14:57:12 INFO SparkContext: Added JAR file:/home/muelleki/R/x86_64-pc-linux-gnu-library/3.4/sparklyr/java/commons-csv-1.1.jar at http://127.0.0.1:39741/jars/commons-csv-1.1.jar with timestamp 1498222632411 +17/06/23 14:57:12 INFO SparkContext: Added JAR file:/home/muelleki/R/x86_64-pc-linux-gnu-library/3.4/sparklyr/java/univocity-parsers-1.5.1.jar at http://127.0.0.1:39741/jars/univocity-parsers-1.5.1.jar with timestamp 1498222632411 +17/06/23 14:57:12 INFO SparkContext: Added JAR file:/home/muelleki/R/x86_64-pc-linux-gnu-library/3.4/sparklyr/java/sparklyr-1.6-2.10.jar at http://127.0.0.1:39741/jars/sparklyr-1.6-2.10.jar with timestamp 1498222632412 +17/06/23 14:57:12 INFO Executor: Starting executor ID driver on host localhost +17/06/23 14:57:12 INFO Utils: Successfully started service 'org.apache.spark.network.netty.NettyBlockTransferService' on port 35727. +17/06/23 14:57:12 INFO NettyBlockTransferService: Server created on 35727 +17/06/23 14:57:12 INFO BlockManagerMaster: Trying to register BlockManager +17/06/23 14:57:12 INFO BlockManagerMasterEndpoint: Registering block manager localhost:35727 with 511.1 MB RAM, BlockManagerId(driver, localhost, 35727) +17/06/23 14:57:12 INFO BlockManagerMaster: Registered BlockManager +17/06/23 14:57:13 INFO HiveContext: Initializing execution hive, version 1.2.1 +17/06/23 14:57:13 INFO ClientWrapper: Inspected Hadoop version: 2.6.0 +17/06/23 14:57:13 INFO ClientWrapper: Loaded org.apache.hadoop.hive.shims.Hadoop23Shims for Hadoop version 2.6.0 +17/06/23 14:57:13 INFO HiveMetaStore: 0: Opening raw store with implemenation class:org.apache.hadoop.hive.metastore.ObjectStore +17/06/23 14:57:13 INFO ObjectStore: ObjectStore, initialize called +17/06/23 14:57:13 INFO Persistence: Property hive.metastore.integral.jdo.pushdown unknown - will be ignored +17/06/23 14:57:13 INFO Persistence: Property datanucleus.cache.level2 unknown - will be ignored +17/06/23 14:57:13 WARN Connection: BoneCP specified but not present in CLASSPATH (or one of dependencies) +17/06/23 14:57:13 WARN Connection: BoneCP specified but not present in CLASSPATH (or one of dependencies) +17/06/23 14:57:15 INFO ObjectStore: Setting MetaStore object pin classes with hive.metastore.cache.pinobjtypes="Table,StorageDescriptor,SerDeInfo,Partition,Database,Type,FieldSchema,Order" +17/06/23 14:57:16 INFO Datastore: The class "org.apache.hadoop.hive.metastore.model.MFieldSchema" is tagged as "embedded-only" so does not have its own datastore table. +17/06/23 14:57:16 INFO Datastore: The class "org.apache.hadoop.hive.metastore.model.MOrder" is tagged as "embedded-only" so does not have its own datastore table. +17/06/23 14:57:17 INFO Datastore: The class "org.apache.hadoop.hive.metastore.model.MFieldSchema" is tagged as "embedded-only" so does not have its own datastore table. +17/06/23 14:57:17 INFO Datastore: The class "org.apache.hadoop.hive.metastore.model.MOrder" is tagged as "embedded-only" so does not have its own datastore table. +17/06/23 14:57:17 INFO MetaStoreDirectSql: Using direct SQL, underlying DB is DERBY +17/06/23 14:57:17 INFO ObjectStore: Initialized ObjectStore +17/06/23 14:57:17 WARN ObjectStore: Version information not found in metastore. hive.metastore.schema.verification is not enabled so recording the schema version 1.2.0 +17/06/23 14:57:17 WARN ObjectStore: Failed to get database default, returning NoSuchObjectException +17/06/23 14:57:18 INFO HiveMetaStore: Added admin role in metastore +17/06/23 14:57:18 INFO HiveMetaStore: Added public role in metastore +17/06/23 14:57:18 INFO HiveMetaStore: No user is added in admin role, since config is empty +17/06/23 14:57:18 INFO HiveMetaStore: 0: get_all_databases +17/06/23 14:57:18 INFO audit: ugi=muelleki ip=unknown-ip-addr cmd=get_all_databases +17/06/23 14:57:18 INFO HiveMetaStore: 0: get_functions: db=default pat=* +17/06/23 14:57:18 INFO audit: ugi=muelleki ip=unknown-ip-addr cmd=get_functions: db=default pat=* +17/06/23 14:57:18 INFO Datastore: The class "org.apache.hadoop.hive.metastore.model.MResourceUri" is tagged as "embedded-only" so does not have its own datastore table. +17/06/23 14:57:18 INFO SessionState: Created HDFS directory: /tmp/hive/muelleki +17/06/23 14:57:18 INFO SessionState: Created local directory: /tmp/muelleki +17/06/23 14:57:18 INFO SessionState: Created local directory: /tmp/8b6c6fe1-5d40-4065-9788-393d277a88ef_resources +17/06/23 14:57:18 INFO SessionState: Created HDFS directory: /tmp/hive/muelleki/8b6c6fe1-5d40-4065-9788-393d277a88ef +17/06/23 14:57:18 INFO SessionState: Created local directory: /tmp/muelleki/8b6c6fe1-5d40-4065-9788-393d277a88ef +17/06/23 14:57:18 INFO SessionState: Created HDFS directory: /tmp/hive/muelleki/8b6c6fe1-5d40-4065-9788-393d277a88ef/_tmp_space.db +17/06/23 14:57:18 INFO HiveContext: default warehouse location is /user/hive/warehouse +17/06/23 14:57:18 INFO HiveContext: Initializing HiveMetastoreConnection version 1.2.1 using Spark classes. +17/06/23 14:57:18 INFO ClientWrapper: Inspected Hadoop version: 2.6.0 +17/06/23 14:57:18 INFO ClientWrapper: Loaded org.apache.hadoop.hive.shims.Hadoop23Shims for Hadoop version 2.6.0 +17/06/23 14:57:18 INFO HiveMetaStore: 0: Opening raw store with implemenation class:org.apache.hadoop.hive.metastore.ObjectStore +17/06/23 14:57:18 INFO ObjectStore: ObjectStore, initialize called +17/06/23 14:57:19 INFO Persistence: Property hive.metastore.integral.jdo.pushdown unknown - will be ignored +17/06/23 14:57:19 INFO Persistence: Property datanucleus.cache.level2 unknown - will be ignored +17/06/23 14:57:19 WARN Connection: BoneCP specified but not present in CLASSPATH (or one of dependencies) +17/06/23 14:57:19 WARN Connection: BoneCP specified but not present in CLASSPATH (or one of dependencies) +17/06/23 14:57:19 INFO ObjectStore: Setting MetaStore object pin classes with hive.metastore.cache.pinobjtypes="Table,StorageDescriptor,SerDeInfo,Partition,Database,Type,FieldSchema,Order" +17/06/23 14:57:20 INFO Datastore: The class "org.apache.hadoop.hive.metastore.model.MFieldSchema" is tagged as "embedded-only" so does not have its own datastore table. +17/06/23 14:57:20 INFO Datastore: The class "org.apache.hadoop.hive.metastore.model.MOrder" is tagged as "embedded-only" so does not have its own datastore table. +17/06/23 14:57:20 INFO Datastore: The class "org.apache.hadoop.hive.metastore.model.MFieldSchema" is tagged as "embedded-only" so does not have its own datastore table. +17/06/23 14:57:20 INFO Datastore: The class "org.apache.hadoop.hive.metastore.model.MOrder" is tagged as "embedded-only" so does not have its own datastore table. +17/06/23 14:57:20 INFO MetaStoreDirectSql: Using direct SQL, underlying DB is DERBY +17/06/23 14:57:20 INFO ObjectStore: Initialized ObjectStore +17/06/23 14:57:20 WARN ObjectStore: Version information not found in metastore. hive.metastore.schema.verification is not enabled so recording the schema version 1.2.0 +17/06/23 14:57:20 WARN ObjectStore: Failed to get database default, returning NoSuchObjectException +17/06/23 14:57:21 INFO HiveMetaStore: Added admin role in metastore +17/06/23 14:57:21 INFO HiveMetaStore: Added public role in metastore +17/06/23 14:57:21 INFO HiveMetaStore: No user is added in admin role, since config is empty +17/06/23 14:57:21 INFO HiveMetaStore: 0: get_all_databases +17/06/23 14:57:21 INFO audit: ugi=muelleki ip=unknown-ip-addr cmd=get_all_databases +17/06/23 14:57:21 INFO HiveMetaStore: 0: get_functions: db=default pat=* +17/06/23 14:57:21 INFO audit: ugi=muelleki ip=unknown-ip-addr cmd=get_functions: db=default pat=* +17/06/23 14:57:21 INFO Datastore: The class "org.apache.hadoop.hive.metastore.model.MResourceUri" is tagged as "embedded-only" so does not have its own datastore table. +17/06/23 14:57:21 INFO SessionState: Created local directory: /tmp/61f168d6-0853-46e7-8b75-4767f5503c28_resources +17/06/23 14:57:21 INFO SessionState: Created HDFS directory: /tmp/hive/muelleki/61f168d6-0853-46e7-8b75-4767f5503c28 +17/06/23 14:57:21 INFO SessionState: Created local directory: /tmp/muelleki/61f168d6-0853-46e7-8b75-4767f5503c28 +17/06/23 14:57:21 INFO SessionState: Created HDFS directory: /tmp/hive/muelleki/61f168d6-0853-46e7-8b75-4767f5503c28/_tmp_space.db +17/06/23 14:57:31 INFO ParseDriver: Parsing command: CREATE TABLE new_df AS SELECT * FROM df WHERE u rlike '.*hello.*' +17/06/23 14:57:32 INFO ParseDriver: Parse Completed +17/06/23 14:57:32 INFO HiveMetaStore: 0: get_table : db=default tbl=df +17/06/23 14:57:32 INFO audit: ugi=muelleki ip=unknown-ip-addr cmd=get_table : db=default tbl=df +17/06/23 14:57:43 INFO ParseDriver: Parsing command: SELECT 1 +17/06/23 14:57:43 INFO ParseDriver: Parse Completed +17/06/23 14:57:43 INFO SparkContext: Starting job: collect at utils.scala:195 +17/06/23 14:57:43 INFO DAGScheduler: Got job 0 (collect at utils.scala:195) with 1 output partitions +17/06/23 14:57:43 INFO DAGScheduler: Final stage: ResultStage 0 (collect at utils.scala:195) +17/06/23 14:57:43 INFO DAGScheduler: Parents of final stage: List() +17/06/23 14:57:43 INFO DAGScheduler: Missing parents: List() +17/06/23 14:57:43 INFO DAGScheduler: Submitting ResultStage 0 (MapPartitionsRDD[2] at collect at utils.scala:195), which has no missing parents +17/06/23 14:57:43 INFO MemoryStore: Block broadcast_0 stored as values in memory (estimated size 4.7 KB, free 4.7 KB) +17/06/23 14:57:43 INFO MemoryStore: Block broadcast_0_piece0 stored as bytes in memory (estimated size 2.7 KB, free 7.4 KB) +17/06/23 14:57:43 INFO BlockManagerInfo: Added broadcast_0_piece0 in memory on localhost:35727 (size: 2.7 KB, free: 511.1 MB) +17/06/23 14:57:43 INFO SparkContext: Created broadcast 0 from broadcast at DAGScheduler.scala:1006 +17/06/23 14:57:43 INFO DAGScheduler: Submitting 1 missing tasks from ResultStage 0 (MapPartitionsRDD[2] at collect at utils.scala:195) +17/06/23 14:57:43 INFO TaskSchedulerImpl: Adding task set 0.0 with 1 tasks +17/06/23 14:57:43 INFO TaskSetManager: Starting task 0.0 in stage 0.0 (TID 0, localhost, partition 0,PROCESS_LOCAL, 2535 bytes) +17/06/23 14:57:43 INFO Executor: Running task 0.0 in stage 0.0 (TID 0) +17/06/23 14:57:43 INFO Executor: Fetching http://127.0.0.1:39741/jars/univocity-parsers-1.5.1.jar with timestamp 1498222632411 +17/06/23 14:57:43 INFO Utils: Fetching http://127.0.0.1:39741/jars/univocity-parsers-1.5.1.jar to /tmp/spark-4f8a42c0-4e89-4860-bc01-893ad3442212/userFiles-fb90e0ef-1224-44a1-a472-a416ff27830d/fetchFileTemp8535681141781819418.tmp +17/06/23 14:57:43 INFO Executor: Adding file:/tmp/spark-4f8a42c0-4e89-4860-bc01-893ad3442212/userFiles-fb90e0ef-1224-44a1-a472-a416ff27830d/univocity-parsers-1.5.1.jar to class loader +17/06/23 14:57:43 INFO Executor: Fetching http://127.0.0.1:39741/jars/sparklyr-1.6-2.10.jar with timestamp 1498222632412 +17/06/23 14:57:43 INFO Utils: Fetching http://127.0.0.1:39741/jars/sparklyr-1.6-2.10.jar to /tmp/spark-4f8a42c0-4e89-4860-bc01-893ad3442212/userFiles-fb90e0ef-1224-44a1-a472-a416ff27830d/fetchFileTemp6988257835744908057.tmp +17/06/23 14:57:43 INFO Executor: Adding file:/tmp/spark-4f8a42c0-4e89-4860-bc01-893ad3442212/userFiles-fb90e0ef-1224-44a1-a472-a416ff27830d/sparklyr-1.6-2.10.jar to class loader +17/06/23 14:57:43 INFO Executor: Fetching http://127.0.0.1:39741/jars/spark-csv_2.11-1.3.0.jar with timestamp 1498222632410 +17/06/23 14:57:43 INFO Utils: Fetching http://127.0.0.1:39741/jars/spark-csv_2.11-1.3.0.jar to /tmp/spark-4f8a42c0-4e89-4860-bc01-893ad3442212/userFiles-fb90e0ef-1224-44a1-a472-a416ff27830d/fetchFileTemp3953390855796001920.tmp +17/06/23 14:57:43 INFO Executor: Adding file:/tmp/spark-4f8a42c0-4e89-4860-bc01-893ad3442212/userFiles-fb90e0ef-1224-44a1-a472-a416ff27830d/spark-csv_2.11-1.3.0.jar to class loader +17/06/23 14:57:43 INFO Executor: Fetching http://127.0.0.1:39741/jars/commons-csv-1.1.jar with timestamp 1498222632411 +17/06/23 14:57:43 INFO Utils: Fetching http://127.0.0.1:39741/jars/commons-csv-1.1.jar to /tmp/spark-4f8a42c0-4e89-4860-bc01-893ad3442212/userFiles-fb90e0ef-1224-44a1-a472-a416ff27830d/fetchFileTemp4765010594823292181.tmp +17/06/23 14:57:43 INFO Executor: Adding file:/tmp/spark-4f8a42c0-4e89-4860-bc01-893ad3442212/userFiles-fb90e0ef-1224-44a1-a472-a416ff27830d/commons-csv-1.1.jar to class loader +17/06/23 14:57:44 INFO GenerateUnsafeProjection: Code generated in 81.366073 ms +17/06/23 14:57:44 INFO Executor: Finished task 0.0 in stage 0.0 (TID 0). 1306 bytes result sent to driver +17/06/23 14:57:44 INFO TaskSetManager: Finished task 0.0 in stage 0.0 (TID 0) in 216 ms on localhost (1/1) +17/06/23 14:57:44 INFO TaskSchedulerImpl: Removed TaskSet 0.0, whose tasks have all completed, from pool +17/06/23 14:57:44 INFO DAGScheduler: ResultStage 0 (collect at utils.scala:195) finished in 0.226 s +17/06/23 14:57:44 INFO DAGScheduler: Job 0 finished: collect at utils.scala:195, took 0.318829 s +17/06/23 14:58:11 INFO ParseDriver: Parsing command: CREATE TABLE a AS SELECT 1 AS a +17/06/23 14:58:11 INFO ParseDriver: Parse Completed +17/06/23 14:58:11 INFO HiveMetaStore: 0: get_table : db=default tbl=a +17/06/23 14:58:11 INFO audit: ugi=muelleki ip=unknown-ip-addr cmd=get_table : db=default tbl=a +17/06/23 14:58:12 INFO HiveMetaStore: 0: create_table: Table(tableName:a, dbName:default, owner:muelleki, createTime:1498222692, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:int, comment:null)], location:null, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}, skewedInfo:SkewedInfo(skewedColNames:[], skewedColValues:[], skewedColValueLocationMaps:{})), partitionKeys:[], parameters:{}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE, privileges:PrincipalPrivilegeSet(userPrivileges:{}, groupPrivileges:null, rolePrivileges:null)) +17/06/23 14:58:12 INFO audit: ugi=muelleki ip=unknown-ip-addr cmd=create_table: Table(tableName:a, dbName:default, owner:muelleki, createTime:1498222692, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:[FieldSchema(name:a, type:int, comment:null)], location:null, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=1}), bucketCols:[], sortCols:[], parameters:{}, skewedInfo:SkewedInfo(skewedColNames:[], skewedColValues:[], skewedColValueLocationMaps:{})), partitionKeys:[], parameters:{}, viewOriginalText:null, viewExpandedText:null, tableType:MANAGED_TABLE, privileges:PrincipalPrivilegeSet(userPrivileges:{}, groupPrivileges:null, rolePrivileges:null)) +17/06/23 14:58:12 INFO FileUtils: Creating directory if it doesn't exist: file:/user/hive/warehouse/a +17/06/23 15:27:12 INFO BlockManagerInfo: Removed broadcast_0_piece0 on localhost:35727 in memory (size: 2.7 KB, free: 511.1 MB) +17/06/23 15:27:12 INFO ContextCleaner: Cleaned accumulator 3 +17/06/23 15:51:35 INFO SparkContext: Invoking stop() from shutdown hook +17/06/23 15:51:35 INFO SparkUI: Stopped Spark web UI at http://127.0.0.1:4040 +17/06/23 15:51:35 INFO MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped! +17/06/23 15:51:35 INFO MemoryStore: MemoryStore cleared +17/06/23 15:51:35 INFO BlockManager: BlockManager stopped +17/06/23 15:51:35 INFO BlockManagerMaster: BlockManagerMaster stopped +17/06/23 15:51:35 INFO OutputCommitCoordinator$OutputCommitCoordinatorEndpoint: OutputCommitCoordinator stopped! +17/06/23 15:51:35 INFO SparkContext: Successfully stopped SparkContext +17/06/23 15:51:35 INFO ShutdownHookManager: Shutdown hook called +17/06/23 15:51:35 INFO RemoteActorRefProvider$RemotingTerminator: Shutting down remote daemon. +17/06/23 15:51:35 INFO ShutdownHookManager: Deleting directory /tmp/spark-4f8a42c0-4e89-4860-bc01-893ad3442212 +17/06/23 15:51:35 INFO ShutdownHookManager: Deleting directory /tmp/spark-eb798167-4372-4f35-8bb7-2fbdcf3fc807 +17/06/23 15:51:35 INFO RemoteActorRefProvider$RemotingTerminator: Remote daemon shut down; proceeding with flushing remote transports. +17/06/23 15:51:35 INFO ShutdownHookManager: Deleting directory /tmp/spark-4f8a42c0-4e89-4860-bc01-893ad3442212/httpd-7d9ae7e3-2484-4c55-b7f5-07d25d13cbea diff --git a/man/create_node_from_nested_root.Rd b/man/create_node_from_nested_root.Rd index 887c91e5a..1c30750e9 100644 --- a/man/create_node_from_nested_root.Rd +++ b/man/create_node_from_nested_root.Rd @@ -21,7 +21,7 @@ This function is convenient to display all nesting levels of a nested tibble at once. } \examples{ -if (getRversion() >= 3.2) { +if (rlang::is_installed("data.tree")) { code <- "a <- function(x) { if(x > 1) { 1+1 } else {x} }" nested_pd <- styler:::compute_parse_data_nested(code) initialized <- styler:::pre_visit(nested_pd, c(default_style_guide_attributes)) diff --git a/man/equals_style.Rd b/man/equals_style.Rd new file mode 100644 index 000000000..16a352992 --- /dev/null +++ b/man/equals_style.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/style-guides.R +\name{equals_style} +\alias{equals_style} +\title{Equals assignment style} +\usage{ +equals_style() +} +\description{ +Use equals assignment instead of arrow assignment. +} +\details{ +This style guide is the same as \code{\link[=tidyverse_style]{tidyverse_style()}}, except it uses +equals (\code{=}) rather than arrow \code{<-} assignment. +} +\examples{ +style_text("x <- 1", style = equals_style) +} +\seealso{ +Other style_guides: \code{\link{tidyverse_style}} +} +\concept{style_guides} diff --git a/man/tidyverse_style.Rd b/man/tidyverse_style.Rd index f23a3fef0..df648fa3e 100644 --- a/man/tidyverse_style.Rd +++ b/man/tidyverse_style.Rd @@ -59,5 +59,8 @@ style_text("call( 1)", transformers = tidyverse_style(strict = TRUE)) style_text(c("ab <- 3", "a <-3"), strict = FALSE) # keeps alignment of "<-" style_text(c("ab <- 3", "a <-3"), strict = TRUE) # drops alignment of "<-" } +\seealso{ +Other style_guides: \code{\link{equals_style}} +} \concept{obtain transformers} \concept{style_guides} diff --git a/switch.R b/switch.R new file mode 100644 index 000000000..47f7ee761 --- /dev/null +++ b/switch.R @@ -0,0 +1,13 @@ +code <- ' +call( + fun(1), + 2, + 3 +) +' + +y <- + code %>% compute_parse_data_nested %>% create_filler_nested + +y %>% create_node_from_nested_root + diff --git a/test.txt b/test.txt new file mode 100644 index 000000000..59005ad05 --- /dev/null +++ b/test.txt @@ -0,0 +1,24 @@ +# A tibble: 1 x 13 +spaces newlines short line1 col1 line2 col2 id parent token terminal + + 1 0 0 "f(\n1," 1 1 3 2 21 0 expr FALSE +| +| + # A tibble: 8 x 13 + spaces newlines short line1 col1 line2 col2 id parent token terminal + + 1 0 0 f 1 1 1 1 3 21 expr FALSE + # A tibble: 1 x 13 + spaces newlines short line1 col1 line2 col2 id parent token + + 1 0 0 f 1 1 1 1 1 3 SYMBOL_FUNCTION_CALL + # ... with 3 more variables: terminal , text , child + + 2 0 1 ( 1 2 1 2 2 21 '(' TRUE + 3 0 0 1 2 1 2 1 6 21 expr FALSE + 4 1 0 , 2 2 2 2 7 21 ',' TRUE + 5 0 0 2 2 4 2 4 11 21 expr FALSE + 6 0 1 , 2 5 2 5 12 21 ',' TRUE + 7 0 0 3 3 1 3 1 17 21 expr FALSE + 8 0 0 ) 3 2 3 2 18 21 ')' TRUE + # ... with 2 more variables: child , text