我有在R Markdown中运行良好的代码。它本身也可以在R中正常运行。然后,我安装了knitr以便能够访问外部代码块,现在出现以下错误。我已经运行update.packages()
,一切都保持最新状态。
Error in .Call(C_stri_flatten, str, collapse, na_empty, omit_empty) :
Incorrect number of arguments (4), expecting 2 for 'C_stri_flatten'
Calls: <Anonymous> ... stri_wrap -> sapply -> lapply -> FUN -> stri_flatten ->
.Call
我使用的结构具有来自外部文件的降价调用代码。在R Markdown代码的早期,通过以下代码将其设置到文件中:
```{r load file, echo=FALSE}
read_chunk('30to90Day.R')
```
的此链接获得了这种语法
抛出错误时正在执行的代码如下:
```{r cleanCols, echo=F}
```
下面的cleanCols
代码是在以上read_chunk('30to90Day.R')
所引用的文件中,使用knitr语法。
## @knitr cleanCols
# rename and clean up
# change the column names
colnames(data) <- c('ClmNbr',
'FeatureNbr',
'SnapshotDay',
'IncSnapshotDay',
'FinalPaid',
'AttyRepresent',
'BILimitPerson',
'InjuryType',
'ClmtAgeAtLoss')
# change ClmNbr to character
data$ClmNbr <- as.character(data$ClmNbr)
# count of na
datatable(data %>% group_by(SnapshotDay) %>%
summarise(count = sum(is.na(IncSnapshotDay))))
# clean up attyrepresent
data$AttyRepresent <- as.character(data$AttyRepresent)
data$AttyRepresent <- as.factor(
ifelse(is.na(data$AttyRepresent), 'Unk', data$AttyRepresent))
# get only the data with values at 30 and 90
dataClean <- data %>% filter (!is.na(IncSnapshotDay))
以上所有代码在R Markdown之外均可正常运行。我的系统环境如下:
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server >= 2012 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bindrcpp_0.2.2 plotly_4.8.0 PerformanceAnalytics_1.5.2
[4] xts_0.11-0 zoo_1.8-3 scales_0.5.0
[7] ggplot2_3.0.0 knitr_1.20 reshape2_1.4.3
[10] DT_0.4 markovchain_0.6.9.11 dplyr_0.7.6
[13] RODBC_1.3-15 RevoUtils_10.0.7 RevoUtilsMath_10.0.1
loaded via a namespace (and not attached):
[1] tidyselect_0.2.3 purrr_0.2.4 lattice_0.20-35 colorspace_1.3-2
[5] expm_0.999-2 viridisLite_0.3.0 htmltools_0.3.6 stats4_3.4.3
[9] yaml_2.1.16 rlang_0.2.1 later_0.7.3 pillar_1.3.0
[13] glue_1.3.0 withr_2.1.2 bindr_0.1.1 plyr_1.8.4
[17] stringr_1.3.1 munsell_0.5.0 gtable_0.2.0 htmlwidgets_1.2
[21] evaluate_0.11 httpuv_1.4.5 crosstalk_1.0.0 parallel_3.4.3
[25] Rcpp_0.12.18 xtable_1.8-2 matlab_1.0.2 promises_1.0.1
[29] backports_1.1.2 jsonlite_1.5 RcppParallel_4.4.1 mime_0.5
[33] digest_0.6.13 stringi_1.2.4 shiny_1.0.5 grid_3.4.3
[37] rprojroot_1.3-2 quadprog_1.5-5 tools_3.4.3 magrittr_1.5
[41] lazyeval_0.2.1 tibble_1.4.2 tidyr_0.7.2 crayon_1.3.4
[45] pkgconfig_2.0.1 Matrix_1.2-14 data.table_1.11.4 assertthat_0.2.0
[49] rmarkdown_1.10 httr_1.3.1 rstudioapi_0.7 R6_2.2.2
[53] igraph_1.2.2 compiler_3.4.3
knitr和rmarkdown之间是否存在冲突?