From 958ddaff17632aa92c370f06b99c777c9f586a8d Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 13 Sep 2022 09:18:45 +0200 Subject: [PATCH 01/11] Implement `ensure_last_n_empty()` --- DESCRIPTION | 4 ++++ NAMESPACE | 1 + R/cpp11.R | 5 +++++ R/styler.R | 5 +++++ R/utils.R | 15 ------------- man/ensure_last_n_empty.Rd | 17 -------------- src/.gitignore | 3 +++ src/cpp11.cpp | 27 ++++++++++++++++++++++ src/ensure_last_n_empty.cpp | 45 +++++++++++++++++++++++++++++++++++++ tests/testthat/test-varia.R | 6 ++--- 10 files changed, 93 insertions(+), 35 deletions(-) create mode 100644 R/cpp11.R delete mode 100644 man/ensure_last_n_empty.Rd create mode 100644 src/.gitignore create mode 100644 src/cpp11.cpp create mode 100644 src/ensure_last_n_empty.cpp diff --git a/DESCRIPTION b/DESCRIPTION index 551b41b65..25209bbf7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -59,6 +59,7 @@ Collate: 'communicate.R' 'compat-dplyr.R' 'compat-tidyr.R' + 'cpp11.R' 'detect-alignment-utils.R' 'detect-alignment.R' 'environments.R' @@ -103,3 +104,6 @@ Collate: 'vertical.R' 'visit.R' 'zzz.R' +LinkingTo: + cpp11 +SystemRequirements: C++11 diff --git a/NAMESPACE b/NAMESPACE index 753e18d53..d20e76680 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -47,3 +47,4 @@ importFrom(rlang,with_handlers) importFrom(utils,capture.output) importFrom(utils,tail) importFrom(utils,write.table) +useDynLib(styler, .registration = TRUE) diff --git a/R/cpp11.R b/R/cpp11.R new file mode 100644 index 000000000..f00cead72 --- /dev/null +++ b/R/cpp11.R @@ -0,0 +1,5 @@ +# Generated by cpp11: do not edit by hand + +ensure_last_n_empty <- function(x, n) { + .Call(`_styler_ensure_last_n_empty`, x, n) +} diff --git a/R/styler.R b/R/styler.R index a6e44e870..517179cf4 100644 --- a/R/styler.R +++ b/R/styler.R @@ -18,6 +18,11 @@ #' style_text("a%>%b; a", scope = "tokens") "_PACKAGE" +## usethis namespace: start +#' @useDynLib styler, .registration = TRUE +## usethis namespace: end +NULL + if (getRversion() >= "2.15.1") { utils::globalVariables(c( ".", diff --git a/R/utils.R b/R/utils.R index 14129e3f4..9d8c1dd6c 100644 --- a/R/utils.R +++ b/R/utils.R @@ -4,21 +4,6 @@ line_col_names <- function() { c("line1", "line2", "col1", "col2") } -#' Ensure there is one (and only one) blank line at the end of a vector -#' @examples -#' styler:::ensure_last_n_empty("") -#' styler:::ensure_last_n_empty(letters) -#' styler:::ensure_last_n_empty(c(letters, "", "", "")) -#' @keywords internal -ensure_last_n_empty <- function(x, n = 1) { - if (all(x == "")) { - return("") - } - x <- c(x, "", "") - x <- x[seq(1, length(x) - which(rev(x) != "")[1] + 1L)] - c(x, rep("", n)) -} - #' Replace the newline character with a line break #' #' @param text A character vector diff --git a/man/ensure_last_n_empty.Rd b/man/ensure_last_n_empty.Rd deleted file mode 100644 index 489a67f2f..000000000 --- a/man/ensure_last_n_empty.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{ensure_last_n_empty} -\alias{ensure_last_n_empty} -\title{Ensure there is one (and only one) blank line at the end of a vector} -\usage{ -ensure_last_n_empty(x, n = 1) -} -\description{ -Ensure there is one (and only one) blank line at the end of a vector -} -\examples{ -styler:::ensure_last_n_empty("") -styler:::ensure_last_n_empty(letters) -styler:::ensure_last_n_empty(c(letters, "", "", "")) -} -\keyword{internal} diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 000000000..22034c461 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,3 @@ +*.o +*.so +*.dll diff --git a/src/cpp11.cpp b/src/cpp11.cpp new file mode 100644 index 000000000..e777d7e5f --- /dev/null +++ b/src/cpp11.cpp @@ -0,0 +1,27 @@ +// Generated by cpp11: do not edit by hand +// clang-format off + + +#include "cpp11/declarations.hpp" +#include + +// ensure_last_n_empty.cpp +std::vector ensure_last_n_empty(std::vector x, int n); +extern "C" SEXP _styler_ensure_last_n_empty(SEXP x, SEXP n) { + BEGIN_CPP11 + return cpp11::as_sexp(ensure_last_n_empty(cpp11::as_cpp>>(x), cpp11::as_cpp>(n))); + END_CPP11 +} + +extern "C" { +static const R_CallMethodDef CallEntries[] = { + {"_styler_ensure_last_n_empty", (DL_FUNC) &_styler_ensure_last_n_empty, 2}, + {NULL, NULL, 0} +}; +} + +extern "C" attribute_visible void R_init_styler(DllInfo* dll){ + R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); + R_useDynamicSymbols(dll, FALSE); + R_forceSymbols(dll, TRUE); +} diff --git a/src/ensure_last_n_empty.cpp b/src/ensure_last_n_empty.cpp new file mode 100644 index 000000000..d7dfcb0c7 --- /dev/null +++ b/src/ensure_last_n_empty.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include +using namespace cpp11; + +//' Ensure there is one (and only one) blank line at the end of a vector +//' @examples +//' styler:::ensure_last_n_empty("") +//' styler:::ensure_last_n_empty(letters) +//' styler:::ensure_last_n_empty(c(letters, "", "", "")) +//' @keywords internal +[[cpp11::register]] +std::vector ensure_last_n_empty(std::vector x, int n = 1) +{ + + // Return early if all elements are empty + // There should be only single empty element, no matter the value of `n` + if (std::all_of(x.begin(), x.end(), [](std::string s) + { return s == ""; })) + { + std::vector x{""}; + return x; + } + + // If an empty element isn't found at the end, add `n` of them + if (x.back() != "" && n > 0) + { + std::fill_n(std::back_inserter(x), n, ""); + return x; + } + + // If one or many empty elements are present at the end of x, remove them and add n of "" + if (x.back() == "") + { + auto it = std::find_if(x.rbegin(), x.rend(), [](std::string s) + { return s != ""; }); + x.erase(it.base(), x.end()); + std::fill_n(std::back_inserter(x), n, ""); + return x; + } + + return x; +} + diff --git a/tests/testthat/test-varia.R b/tests/testthat/test-varia.R index 422363a0d..ce5d26796 100644 --- a/tests/testthat/test-varia.R +++ b/tests/testthat/test-varia.R @@ -2,15 +2,15 @@ test_that("ensure_last_n_empty", { expect_equal( - ensure_last_n_empty("x"), + ensure_last_n_empty("x", 1L), c("x", "") ) expect_equal( - ensure_last_n_empty(c("x", "")), + ensure_last_n_empty(c("x", ""), 1L), c("x", "") ) expect_equal( - ensure_last_n_empty(c("1", "2")), + ensure_last_n_empty(c("1", "2"), 1L), c("1", "2", "") ) }) From 1faef18726aefb28a358c89fe3e32f748bffc4ea Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 13 Sep 2022 07:21:17 +0000 Subject: [PATCH 02/11] pre-commit --- inst/WORDLIST | 19 +++++++++++++++++++ src/.gitignore | 2 +- src/ensure_last_n_empty.cpp | 1 - 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/inst/WORDLIST b/inst/WORDLIST index d68d4b358..951985458 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -15,6 +15,8 @@ benchmarking biocthis bootswatch BugReports +CallEntries +CallMethodDef cancelling cff chnages @@ -26,6 +28,7 @@ coercible compat config CONST +const coventions covr cpp @@ -40,6 +43,9 @@ desc dev devtools dir +DL +dll +DllInfo docsearch dont dontrun @@ -62,10 +68,13 @@ examplesIf exampletestr expr expr EQ +extern fileext filetype +forceSymbols forcond formatter +FUNC funct gadenbuie gcc @@ -81,6 +90,7 @@ grkstyle GSOC hashFiles helpfiles +hpp href http https @@ -89,8 +99,10 @@ ifelse impl Indrajeet infinitively +init initializer inode +inserter integrations interaces invasiveness @@ -112,6 +124,7 @@ LF LIBS lifecycle Ligges +LinkingTo lintr linux lorenz @@ -161,6 +174,7 @@ purrr qmd Qmd questionr +rbegin rcmdcheck RcppExports rds @@ -168,6 +182,7 @@ readline readme README rebased +registerRoutines reindent reindented reindention @@ -217,6 +232,8 @@ sessioninfo setCacheRootPath setdiff setenv +sexp +SEXP shinydashboardPlus shinymeta shinyMonacoEditor @@ -241,6 +258,7 @@ Sys sysreq sysreqs systemPipeShiny +SystemRequirements tempfile testthat tibble @@ -268,6 +286,7 @@ unnest unparsable unstyled upsetjs +useDynamicSymbols usethis utf Uwe diff --git a/src/.gitignore b/src/.gitignore index 22034c461..2f843a5dc 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,3 +1,3 @@ +*.dll *.o *.so -*.dll diff --git a/src/ensure_last_n_empty.cpp b/src/ensure_last_n_empty.cpp index d7dfcb0c7..d9c7e8143 100644 --- a/src/ensure_last_n_empty.cpp +++ b/src/ensure_last_n_empty.cpp @@ -42,4 +42,3 @@ std::vector ensure_last_n_empty(std::vector x, int n = return x; } - From 01a6f31d853798e88433fe000aea1166b22c688a Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 13 Sep 2022 09:28:21 +0200 Subject: [PATCH 03/11] better formatting --- src/ensure_last_n_empty.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/ensure_last_n_empty.cpp b/src/ensure_last_n_empty.cpp index d9c7e8143..262983eb7 100644 --- a/src/ensure_last_n_empty.cpp +++ b/src/ensure_last_n_empty.cpp @@ -16,8 +16,7 @@ std::vector ensure_last_n_empty(std::vector x, int n = // Return early if all elements are empty // There should be only single empty element, no matter the value of `n` - if (std::all_of(x.begin(), x.end(), [](std::string s) - { return s == ""; })) + if (std::all_of(x.begin(), x.end(), [](std::string s) { return s == ""; })) { std::vector x{""}; return x; @@ -30,15 +29,8 @@ std::vector ensure_last_n_empty(std::vector x, int n = return x; } - // If one or many empty elements are present at the end of x, remove them and add n of "" - if (x.back() == "") - { - auto it = std::find_if(x.rbegin(), x.rend(), [](std::string s) - { return s != ""; }); - x.erase(it.base(), x.end()); - std::fill_n(std::back_inserter(x), n, ""); - return x; - } - + auto it = std::find_if(x.rbegin(), x.rend(), [](std::string s) { return s != ""; }); + x.erase(it.base(), x.end()); + std::fill_n(std::back_inserter(x), n, ""); return x; } From 46c4ecb1e8e5739ee79ffa42e4c00505d85c3449 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 13 Sep 2022 09:40:16 +0200 Subject: [PATCH 04/11] Update .pre-commit-config.yaml --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 24c8f574d..37fafbdad 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,6 +24,7 @@ repos: - r-lib/pkgapi - dplyr@1.0.9 - roxygen2@7.2.1 + - pkgbuild - id: use-tidy-description - id: spell-check exclude: > From 177fdc6613841741ac7a1accb9fece4bfcd9df4f Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 13 Sep 2022 09:49:07 +0200 Subject: [PATCH 05/11] Update .pre-commit-config.yaml --- .pre-commit-config.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 37fafbdad..2b207c13e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,6 +25,9 @@ repos: - dplyr@1.0.9 - roxygen2@7.2.1 - pkgbuild + - brio + - decor + - cpp11 - id: use-tidy-description - id: spell-check exclude: > From e2f99c56ab30b90fba21b347c5de79dec28c1ced Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 13 Sep 2022 09:59:11 +0200 Subject: [PATCH 06/11] Exclude cpp, h, hpp files from spell check --- .pre-commit-config.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2b207c13e..7393df726 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -47,6 +47,9 @@ repos: (.*/|)\.pre-commit-.*| .*\.[rR]| .*\.Rproj| + .*\.cpp| + .*\.h| + .*\.hpp| .*\.py| .*\.feather| .*\.rds| From 09467fc726606abb1cb5ab471c855c5b71505911 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 13 Sep 2022 11:00:43 +0200 Subject: [PATCH 07/11] fix addin; try benchmarking with more iterations --- R/addins.R | 4 ++-- touchstone/script.R | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/R/addins.R b/R/addins.R index a62074d95..7cc1c5c92 100644 --- a/R/addins.R +++ b/R/addins.R @@ -71,8 +71,8 @@ style_active_file <- function() { abort("Can only style .R, .Rmd and .Rnw files.") } rstudioapi::modifyRange( - c(1, 1, length(context$contents) + 1, 1), - paste0(ensure_last_n_empty(out), collapse = "\n"), + c(1L, 1L, length(context$contents) + 1L, 1L), + paste0(ensure_last_n_empty(out, n = 1L), collapse = "\n"), id = context$id ) if (save_after_styling_is_active() == TRUE && context$path != "") { diff --git a/touchstone/script.R b/touchstone/script.R index 1bbcec1df..f3b470abe 100644 --- a/touchstone/script.R +++ b/touchstone/script.R @@ -1,5 +1,7 @@ library(touchstone) +number_of_runs <- 50L + branch_install() clear_branch_caches <- function() { @@ -18,7 +20,7 @@ benchmark_run( cache_deactivate() }, without_cache = style_pkg("touchstone/sources/here", filetype = c("R", "rmd")), - n = 30 + n = number_of_runs ) clear_branch_caches() @@ -28,7 +30,7 @@ benchmark_run( cache_activate(gert::git_branch()) }, cache_applying = style_pkg("touchstone/sources/here", filetype = c("R", "rmd")), - n = 30 + n = number_of_runs ) clear_branch_caches() @@ -42,7 +44,7 @@ benchmark_run( gert::git_reset_hard(repo = "touchstone/sources/here") style_pkg("touchstone/sources/here", filetype = c("R", "rmd")) }, - n = 30 + n = number_of_runs ) clear_branch_caches() From b3a656eeeec6d9e894bab43f98fc64ff246e9fb5 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 13 Sep 2022 20:22:21 +0200 Subject: [PATCH 08/11] convert index helpers check if warnings can be reproduced on CI --- R/cpp11.R | 8 ++++++++ R/utils.R | 11 ----------- src/cpp11.cpp | 16 ++++++++++++++++ src/index_helpers.cpp | 30 ++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 src/index_helpers.cpp diff --git a/R/cpp11.R b/R/cpp11.R index f00cead72..545d8a715 100644 --- a/R/cpp11.R +++ b/R/cpp11.R @@ -3,3 +3,11 @@ ensure_last_n_empty <- function(x, n) { .Call(`_styler_ensure_last_n_empty`, x, n) } + +odd_index <- function(x) { + .Call(`_styler_odd_index`, x) +} + +even_index <- function(x) { + .Call(`_styler_even_index`, x) +} diff --git a/R/utils.R b/R/utils.R index 05086c598..6e18a615f 100644 --- a/R/utils.R +++ b/R/utils.R @@ -24,17 +24,6 @@ convert_newlines_to_linebreaks <- function(text) { unlist(use.names = FALSE) } -odd_index <- function(x) { - if (length(x) < 1) { - return(NULL) - } - seq(1L, length(x), by = 2) -} - -even_index <- function(x) { - seq(2L, length(x), by = 2) -} - is_windows <- function() { identical(.Platform$OS.type, "windows") } diff --git a/src/cpp11.cpp b/src/cpp11.cpp index e777d7e5f..d75cc3eca 100644 --- a/src/cpp11.cpp +++ b/src/cpp11.cpp @@ -12,10 +12,26 @@ extern "C" SEXP _styler_ensure_last_n_empty(SEXP x, SEXP n) { return cpp11::as_sexp(ensure_last_n_empty(cpp11::as_cpp>>(x), cpp11::as_cpp>(n))); END_CPP11 } +// index_helpers.cpp +std::vector odd_index(const sexp x); +extern "C" SEXP _styler_odd_index(SEXP x) { + BEGIN_CPP11 + return cpp11::as_sexp(odd_index(cpp11::as_cpp>(x))); + END_CPP11 +} +// index_helpers.cpp +std::vector even_index(const sexp x); +extern "C" SEXP _styler_even_index(SEXP x) { + BEGIN_CPP11 + return cpp11::as_sexp(even_index(cpp11::as_cpp>(x))); + END_CPP11 +} extern "C" { static const R_CallMethodDef CallEntries[] = { {"_styler_ensure_last_n_empty", (DL_FUNC) &_styler_ensure_last_n_empty, 2}, + {"_styler_even_index", (DL_FUNC) &_styler_even_index, 1}, + {"_styler_odd_index", (DL_FUNC) &_styler_odd_index, 1}, {NULL, NULL, 0} }; } diff --git a/src/index_helpers.cpp b/src/index_helpers.cpp new file mode 100644 index 000000000..7eca93a41 --- /dev/null +++ b/src/index_helpers.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include +using namespace cpp11; + +[[cpp11::register]] +std::vector odd_index(const sexp x) +{ + std::vector odd_indices; + + for (int i = 1; i < Rf_length(x); i += 2) + { + odd_indices.push_back(i); + } + + return odd_indices; +} + +[[cpp11::register]] +std::vector even_index(const sexp x) +{ + std::vector even_indices; + for (int i = 2; i < Rf_length(x); i += 2) + { + even_indices.push_back(i); + } + + return even_indices; +} From 7154cf85814affccbab9816d042bfcc1cd108e9c Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 13 Sep 2022 20:28:55 +0200 Subject: [PATCH 09/11] Revert "convert index helpers" This reverts commit b3a656eeeec6d9e894bab43f98fc64ff246e9fb5. --- R/cpp11.R | 8 -------- R/utils.R | 11 +++++++++++ src/cpp11.cpp | 16 ---------------- src/index_helpers.cpp | 30 ------------------------------ 4 files changed, 11 insertions(+), 54 deletions(-) delete mode 100644 src/index_helpers.cpp diff --git a/R/cpp11.R b/R/cpp11.R index 545d8a715..f00cead72 100644 --- a/R/cpp11.R +++ b/R/cpp11.R @@ -3,11 +3,3 @@ ensure_last_n_empty <- function(x, n) { .Call(`_styler_ensure_last_n_empty`, x, n) } - -odd_index <- function(x) { - .Call(`_styler_odd_index`, x) -} - -even_index <- function(x) { - .Call(`_styler_even_index`, x) -} diff --git a/R/utils.R b/R/utils.R index 6e18a615f..05086c598 100644 --- a/R/utils.R +++ b/R/utils.R @@ -24,6 +24,17 @@ convert_newlines_to_linebreaks <- function(text) { unlist(use.names = FALSE) } +odd_index <- function(x) { + if (length(x) < 1) { + return(NULL) + } + seq(1L, length(x), by = 2) +} + +even_index <- function(x) { + seq(2L, length(x), by = 2) +} + is_windows <- function() { identical(.Platform$OS.type, "windows") } diff --git a/src/cpp11.cpp b/src/cpp11.cpp index d75cc3eca..e777d7e5f 100644 --- a/src/cpp11.cpp +++ b/src/cpp11.cpp @@ -12,26 +12,10 @@ extern "C" SEXP _styler_ensure_last_n_empty(SEXP x, SEXP n) { return cpp11::as_sexp(ensure_last_n_empty(cpp11::as_cpp>>(x), cpp11::as_cpp>(n))); END_CPP11 } -// index_helpers.cpp -std::vector odd_index(const sexp x); -extern "C" SEXP _styler_odd_index(SEXP x) { - BEGIN_CPP11 - return cpp11::as_sexp(odd_index(cpp11::as_cpp>(x))); - END_CPP11 -} -// index_helpers.cpp -std::vector even_index(const sexp x); -extern "C" SEXP _styler_even_index(SEXP x) { - BEGIN_CPP11 - return cpp11::as_sexp(even_index(cpp11::as_cpp>(x))); - END_CPP11 -} extern "C" { static const R_CallMethodDef CallEntries[] = { {"_styler_ensure_last_n_empty", (DL_FUNC) &_styler_ensure_last_n_empty, 2}, - {"_styler_even_index", (DL_FUNC) &_styler_even_index, 1}, - {"_styler_odd_index", (DL_FUNC) &_styler_odd_index, 1}, {NULL, NULL, 0} }; } diff --git a/src/index_helpers.cpp b/src/index_helpers.cpp deleted file mode 100644 index 7eca93a41..000000000 --- a/src/index_helpers.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include -#include -#include -using namespace cpp11; - -[[cpp11::register]] -std::vector odd_index(const sexp x) -{ - std::vector odd_indices; - - for (int i = 1; i < Rf_length(x); i += 2) - { - odd_indices.push_back(i); - } - - return odd_indices; -} - -[[cpp11::register]] -std::vector even_index(const sexp x) -{ - std::vector even_indices; - for (int i = 2; i < Rf_length(x); i += 2) - { - even_indices.push_back(i); - } - - return even_indices; -} From d26bbdd63d91979946d81bbcba8c3e042ad7ba09 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Wed, 14 Sep 2022 09:50:47 +0200 Subject: [PATCH 10/11] Convert `line_col_names()` --- R/cpp11.R | 4 ++++ R/utils.R | 4 ---- src/cpp11.cpp | 8 ++++++++ src/line_col_names.cpp | 10 ++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/line_col_names.cpp diff --git a/R/cpp11.R b/R/cpp11.R index f00cead72..0b27b5732 100644 --- a/R/cpp11.R +++ b/R/cpp11.R @@ -3,3 +3,7 @@ ensure_last_n_empty <- function(x, n) { .Call(`_styler_ensure_last_n_empty`, x, n) } + +line_col_names <- function() { + .Call(`_styler_line_col_names`) +} diff --git a/R/utils.R b/R/utils.R index 421d559ba..c3551a638 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,9 +1,5 @@ parse_text <- function(x) parse_safely(x)[[1L]] -line_col_names <- function() { - c("line1", "line2", "col1", "col2") -} - #' Replace the newline character with a line break #' #' @param text A character vector diff --git a/src/cpp11.cpp b/src/cpp11.cpp index e777d7e5f..44e24b1d2 100644 --- a/src/cpp11.cpp +++ b/src/cpp11.cpp @@ -12,10 +12,18 @@ extern "C" SEXP _styler_ensure_last_n_empty(SEXP x, SEXP n) { return cpp11::as_sexp(ensure_last_n_empty(cpp11::as_cpp>>(x), cpp11::as_cpp>(n))); END_CPP11 } +// line_col_names.cpp +std::vector line_col_names(); +extern "C" SEXP _styler_line_col_names() { + BEGIN_CPP11 + return cpp11::as_sexp(line_col_names()); + END_CPP11 +} extern "C" { static const R_CallMethodDef CallEntries[] = { {"_styler_ensure_last_n_empty", (DL_FUNC) &_styler_ensure_last_n_empty, 2}, + {"_styler_line_col_names", (DL_FUNC) &_styler_line_col_names, 0}, {NULL, NULL, 0} }; } diff --git a/src/line_col_names.cpp b/src/line_col_names.cpp new file mode 100644 index 000000000..9365e994f --- /dev/null +++ b/src/line_col_names.cpp @@ -0,0 +1,10 @@ +#include +#include +#include +using namespace cpp11; +[[cpp11::register]] +std::vector line_col_names() +{ + std::vector x{"line1", "line2", "col1", "col2"}; + return x; +} From 9f4c5a952921062a9ca76900ab815e89d3368c78 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Wed, 14 Sep 2022 10:19:41 +0200 Subject: [PATCH 11/11] reduce number of runs --- touchstone/script.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/touchstone/script.R b/touchstone/script.R index f3b470abe..069eb9ba3 100644 --- a/touchstone/script.R +++ b/touchstone/script.R @@ -1,6 +1,6 @@ library(touchstone) -number_of_runs <- 50L +number_of_runs <- 30L branch_install()