I get 'Error: '\U' used without hex digits in character string starting ""C:\U"' when starting R
Asked Answered
A

11

12

I have the following problem when starting RStudio and when I try to compile a PDF from a .rnw format:

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

When starting RStudio or just R, this is what is inside my console:

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

This kind of appeared from one day to another, and I am not sure what has changed. I tried updating RStudio and my R version, but it did not help. I am running R on Windows.

How can I fix this issue?

Ahithophel answered 30/5, 2017 at 23:45 Comment(1)
Re the answers: Does backslash need to be escaped or not? Some of the answers seem contradictory. Is there some context dependence?Sumach
A
23

I was able to solve this after all:

I had a section inside my .Rprofile file (in Documents) with "\" instead of "/". So I now changed

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

to

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

and that did the trick.

Ahithophel answered 30/5, 2017 at 23:55 Comment(0)
L
7

To make it work, just remove the C:\Users\edmar.campos.cardoso\Dropbox\ and replace all \ with / using the function setwd() to change the working directory in R.

Wrong way:

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

Right way:

setwd('/Users/edmar.campos.cardoso/Dropbox/...')
Linseylinseywoolsey answered 26/9, 2019 at 19:28 Comment(0)
O
3

You can use \\ instead of \. This allows skipping from some characters such as \n which is the end of the line or \t which is tab.

Otterburn answered 23/6, 2019 at 0:42 Comment(0)
L
2

For importing files in R, replace the '\' with (two) '\'. Single '\' probably reads it as escape sequence and hence the file path error.

Levana answered 14/2, 2020 at 3:17 Comment(0)
F
1

I simply change the slash for backslash in the route of the file.

Example:
this instruction trigger the error. setwd("C:/Users\name\Desktop\RStudio")

Instruction fix:

setwd("C:/Users/name/Desktop/RStudio")

Forwhy answered 26/6, 2020 at 15:44 Comment(0)
R
1

Sorry for posting a second answer, but now I think this second answer might be a better solution for the problem (I used both solutions quite simultaneously before):

In the .Rprofile file in "C:\Users\myusername\Documents," I had the following content:

# LanguageServer Setup Start (do not change this chunk)
# to remove this, run languageserversetup::remove_from_rprofile
if (requireNamespace('languageserversetup', quietly = TRUE)) {
  options(langserver_library = 'C:\Users\myusername\Documents/languageserver-library')
  languageserversetup::languageserver_startup()
  unloadNamespace('languageserversetup')
}
# LanguageServer Setup End

So obviously, there were incorrect slashes in options(langserver_library = 'C:\Users\myusername\Documents/languageserver-library').

Check if your file has similar problems. If yes, you should replace \ with /.

Rang answered 23/1 at 18:47 Comment(0)
H
0

When you copy a directory address from properties in Windows and use it in R this happens you should easily use / instead of \.

Holladay answered 27/3, 2021 at 13:8 Comment(0)
R
0

I had the same problem. The source of the problem was similar to Trenton's. My libPath contained \ instead of /. I changed it with the following:

.libPaths("C:\Users\myusername\Documents\R")

Check your libPaths with

.libPaths()

Take good care that you use a folder for which you also have writing rights. Otherwise, you won't be able to install packages and will get a "Permission denied" error! Usually, you won't have writing rights in "C:/Users/myusername/another folder;" instead, your Documents folder is a good choice.

Rang answered 22/1 at 22:3 Comment(0)
S
0

use file.edit(file.path("~", ".Rprofile")) to edit the correct Rprofile and make sure that the file path on windows is referenced either using double "\\" or "/". Once I found this command file.edit(file.path("~", ".Rprofile")), it took a sec to identify the issue and resolve the issue.

Sill answered 22/6 at 19:43 Comment(0)
S
-1

Open the CSV file and save as the file to your "My Documents". Then use this:

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

If it’s text, just change read.csv to read.text.

Septi answered 30/5, 2019 at 22:56 Comment(0)
P
-1

Use two backward slashes instead of one as the argument. That will help you get the output.

For example, like this:

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

Instead of:

data<-read.csv("C:\Users\Vamsi\Downloads\pressure.csv")
Preceptive answered 8/7, 2021 at 5:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.