のソースコードを見てください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)stringpatternreplacementstri_replace_first_fixedstri_replace_first_regex
stri_replace_first_fixedここで見つけることができます。
stri_replace_first_regexここで見つけることができます。
限られた時間と比較的さびた C++ の知識でわかる限り、関数はを使用して引数をstri__replace_allfirstlast_fixedチェックします。そのドキュメントによると、NA に遭遇するとエラーがスローされます。これを超えて完全に追跡する時間はありませんが、このエラーが原因ですべての NA が異常に返される可能性があると思われます。replacementstri_prepare_arg_string