启动 R 时,我收到“错误:'\U' 在以“C:\U””开头的字符串中没有使用十六进制数字

问题描述 投票:0回答:9

启动 RStudio 以及尝试从 .rnw 格式编译 PDF 时遇到以下问题:

Error: '\U' used without hex digits in character string starting ""C:\U"

启动 RStudio 或仅 R 时,这就是我的控制台内的内容:

R version 3.4.0 (2017-04-21) -- "You Stupid Darkness"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

Global .Rprofile loaded!

Error: '\U' used without hex digits in character string starting ""C:\U"

And this happens when I try to compile a PDF:

Global .Rprofile loaded!

Error: '\U' used without hex digits in character string starting ""C:\U"
Execution halted

这种情况一天又一天地出现,我不知道发生了什么变化。我尝试更新 RStudio 和我的 R 版本,但没有帮助。我在 Windows 上运行 R。

如何解决这个问题?

r windows knitr tex
9个回答
21
投票

我最终能够解决这个问题:

我的 .Rprofile 文件(在文档中)中有一个部分,其中包含“\”而不是“/”。 所以我现在改变了

# Set mainfolder for PACKAGE package
options(PACKAGE_MAINFOLDER="C:\Users\...")

# Set mainfolder for PACKAGE package
options(PACKAGE_MAINFOLDER="C:/Users/...")

这就成功了。


6
投票

要使其工作,只需删除

C:\Users\edmar.campos.cardoso\Dropbox\
并将所有
\
替换为
/
,使用函数
setwd()
更改
R
中的工作目录。

错误方式:

setwd('C:\Users\edmar.campos.cardoso\Dropbox\...')

正确方法:

setwd('/Users/edmar.campos.cardoso/Dropbox/...')

3
投票

您可以使用

\\
代替
\
。这允许跳过某些字符,例如
\n
(行尾)或
\t
(制表符)。


2
投票

要在 R 中导入文件,请将“\”替换为(两个)“\”。单个“\”可能将其读取为转义序列,因此导致文件路径错误。


1
投票

我只是将文件路径中的斜杠更改为反斜杠。

示例:
该指令触发错误。 setwd("C:/用户 ame\Desktop\RStudio")

指令修复:

setwd(“C:/用户/名称/桌面/RStudio”)


0
投票

当您从 Windows 中的属性复制目录地址并在 R 中使用它时,您应该轻松使用 / 而不是 \。


0
投票

我也有同样的问题。问题的根源与特伦顿的相似。我创建的 libPath 包含 \ 而不是 /。

我将其更改为以下内容:

.libPaths("C:/Users/myname/myfolder/anotherfolder")

检查你的 libPath

.libPaths()

-1
投票

使用两个反斜杠而不是一个反斜杠作为参数。这将帮助您获得输出。

例如,像这样:

data<-read.csv("C:\\Users\\Vamsi\\Downloads\\pressure.csv")

代替:

data<-read.csv("C:\Users\Vamsi\Downloads\pressure.csv")

-1
投票

打开 CSV 文件并将该文件保存到您的“我的文档”。然后用这个:

[MyData <- read.csv("Data.csv",header = TRUE)]

如果是文本,只需将 read.csv 更改为 read.text

© www.soinside.com 2019 - 2024. All rights reserved.