8
私はR-devの上の非常に特定の状況ではPerlの式\\L\\1
との難しさを経験しています(2017年6月6日と2017年6月16日r72796ビルド):再現するはR 3.5.0でサポートされている正規表現\のLですか?
bib <- readLines("https://raw.githubusercontent.com/HughParsonage/TeXCheckR/master/tests/testthat/lint_bib_in.bib", encoding = "UTF-8")
leading_spaces <- 2
is_field <- grepl("=", bib, fixed = TRUE)
field_width <- nchar(trimws(gsub("[=].*$", "", bib, perl = TRUE)))
widest_field <- max(field_width[is_field])
out <- bib
# Vectorized gsub:
for (line in seq_along(bib)){
# Replace every field line with
# two spaces + field name + spaces required for widest field + space
if (is_field[line]){
spaces_req <- widest_field - field_width[line]
out[line] <-
gsub("^\\s*(\\w+)\\s*[=]\\s*\\{",
paste0(paste0(rep(" ", leading_spaces), collapse = ""),
"\\L\\1",
paste0(rep(" ", spaces_req), collapse = ""),
" = {"),
bib[line],
perl = TRUE)
}
}
# Add commas:
out[is_field] <- gsub("\\}$", "\\},", out[is_field], perl = TRUE)
out[9]
#> R-dev " author"
#> R 3.4.0 " author = {Tony Wood and Amélie Hunter and Michael O'Toole and Prasana Venkataraman and Lucy Carter},"
、それが必要です:
readLines
へ
- ファイルから、エンコードを指定します。
- は、Perlの正規表現で
\\L
または\\U
を使用するには(dput
を使用すると再現しません)。 - UTF-8(上記でアメリのE)を必要とするベクトルの要素を有する文字
- のベクターを使用する
これはR 3.5.0の変化である、または有しますこの場合、私は\\L
を乱用していますか?
見て、あなたは警告されています:[。*これはおそらくバグが含まれている、あなたはそれを使用する場合ので注意してください*](https://cran.r-project.org /bin/windows/base/rdevel.html)。 –
私はスニペットを構築することができませんでした - 'leading_spaces'は何ですか? –
この特定のバグにより、パッケージのR CMDチェックでエラーが発生しています。ノンレプレックスについては申し訳ありませんが、私は編集しました。 – Hugh