のソースコードを見てくださいstr_replace
。
function (string, pattern, replacement)
{
replacement <- fix_replacement(replacement)
switch(type(pattern), empty = , bound = stop("Not implemented",
call. = FALSE), fixed = stri_replace_first_fixed(string,
pattern, replacement, opts_fixed = attr(pattern, "options")),
coll = stri_replace_first_coll(string, pattern, replacement,
opts_collator = attr(pattern, "options")), regex = stri_replace_first_regex(string,
pattern, replacement, opts_regex = attr(pattern,
"options")), )
}
<environment: namespace:stringr>
fix_replacement
これはGithubにある find につながります。これも下に置きました。メイン環境で実行すると、 がfix_replacement(NA)
返されることがわかりますNA
。パッケージの に依存しstri_replace_all_regex
ていることがわかります。stringi
fix_replacement <- function(x) {
stri_replace_all_regex(
stri_replace_all_fixed(x, "$", "\\$"),
"(?<!\\\\)\\\\(\\d)",
"\\$$1")
}
興味深いことに、パラメーター ( your 、、および) を指定して実行すると、stri_replace_first_fixed
とstri_replace_first_regex
の両方が返されます。問題は、とが C++ コードであるため、何が起こっているのかを理解するのが少し難しくなることです。c(NA,NA,NA)
string
pattern
replacement
stri_replace_first_fixed
stri_replace_first_regex
stri_replace_first_fixed
ここで見つけることができます。
stri_replace_first_regex
ここで見つけることができます。
限られた時間と比較的さびた C++ の知識でわかる限り、関数はを使用して引数をstri__replace_allfirstlast_fixed
チェックします。そのドキュメントによると、NA に遭遇するとエラーがスローされます。これを超えて完全に追跡する時間はありませんが、このエラーが原因ですべての NA が異常に返される可能性があると思われます。replacement
stri_prepare_arg_string