From 614857850dfb4d966d05446c6d16913befeb1784 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Thu, 22 Dec 2022 10:05:27 -0600 Subject: [PATCH] preserve the := operator --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/utils.R | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0b38085..93222d8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: formatR Type: Package Title: Format R Code Automatically -Version: 1.13 +Version: 1.13.1 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), person("Ed", "Lee", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index f5f8b2b..c25946a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# CHANGES IN formatR VERSION 1.14 + +- `tidy_source()` supports the `:=` operator now (which is widely used in **data.table**). + # CHANGES IN formatR VERSION 1.13 - `tidy_source()` supports anonymous functions of the form `\(args) expr` for R >= 4.1.0 now (thanks, @notPlancha, #98). diff --git a/R/utils.R b/R/utils.R index 6da183d..8c17f79 100644 --- a/R/utils.R +++ b/R/utils.R @@ -65,6 +65,8 @@ mask_comments = function(x, comment, blank.line, wrap, arrow, pipe, args.newline d.text[d.text == '|>'] = paste0('%', '\b|>', spaces, '%') # preserve the assignment operator -> d.text[d.text == '->'] = '%\b->%' + # preserve := for data.table + d.text[d.text == ':='] = '%\b:=%' # R 4.1.0 anonymous functions if (length(i <- which(d.token == "'\\\\'"))) { d.text[i] = '`\\\\`'