在RStudio中输入时无故弹出错误信息的问题求助
问题描述
在RStudio中仅输入字符(未按回车键)时,反复弹出以下错误提示:
Error in gsub(reStrip, "", completions, perl = TRUE) : input string 1 is invalid UTF-8
单独使用R无此问题,已尝试卸载重装RStudio但无效,当前环境的sessionInfo()输出如下:
R version 4.3.1 (2023-06-16 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 11 x64 (build 22621) Matrix products: default locale: [1] LC_COLLATE=Swedish_Sweden.utf8 LC_CTYPE=Swedish_Sweden.utf8 [3] LC_MONETARY=Swedish_Sweden.utf8 LC_NUMERIC=C [5] LC_TIME=Swedish_Sweden.utf8 time zone: Europe/Paris tzcode source: internal attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] utf8_1.2.3 R6_2.5.1 magrittr_2.0.3 gtable_0.3.4 [5] glue_1.6.2 tibble_3.2.1 pkgconfig_2.0.3 lifecycle_1.0.3 [9] ggplot2_3.4.3 cli_3.6.1 fansi_1.0.4 scales_1.2.1 [13] grid_4.3.1 vctrs_0.6.3 compiler_4.3.1 tools_4.3.1 [17] munsell_0.5.0 pillar_1.9.0 colorspace_2.1-0 rlang_1.1.1
排查与解决方法
调整系统UTF-8区域设置:
打开Windows设置→时间和语言→语言和区域→管理语言设置→更改系统区域设置,勾选「Beta版:使用Unicode UTF-8提供全球语言支持」,重启电脑后测试。若担心影响其他软件,也可在RStudio启动时临时设置locale:在控制台执行Sys.setlocale(category = "LC_ALL", locale = "English_United States.utf8"),再输入字符验证。清除RStudio补全缓存:
关闭RStudio,找到缓存目录%APPDATA%\RStudio,删除其中的completions文件夹,重启RStudio后尝试输入字符。排查并更新R包:
部分包的元数据或文档可能包含非UTF-8字符,触发补全错误。执行update.packages(ask = FALSE)更新所有包,若问题仍存在,尝试卸载最近安装的包,逐一排查是否为包的问题。更换RStudio版本:
当前使用的RStudio版本可能存在UTF-8处理bug,尝试安装旧稳定版或预览版(如2023.06.2版本,与R 4.3.1兼容),测试问题是否消失。
内容的提问来源于stack exchange,提问作者Magnus
相关产品推荐
相关产品推荐

