“字符串中无法识别的转义”在尝试读取CSV文件时 [英] "Unrecognized escape in character string" while attempting to read a CSV file

查看:1323
本文介绍了“字符串中无法识别的转义”在尝试读取CSV文件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试导入 .csv 文件,以便我可以关注此视频: R ggplot2图形直方图

I am trying to import a .csv file, so that I can follow along with this video: R ggplot2 Graphics Histograms.

我安装了所有正确的软件包,包括 ggplot 和相关软件包。视频中的第一条指令表示输入 afl.df = read.csv(afl_2003_2007.csv)

I installed all proper packages including ggplot and related packages. The first instruction in the video says to type afl.df=read.csv("afl_2003_2007.csv")

所以,我下载了 afl_2003_2007.csv 文件,我尝试了以下所有内容,基本上将文件放在不同的目录中(共享驱动器,然后是C驱动器等) 。我也尝试使用 setwd ,但没有运气。

So, I downloaded afl_2003_2007.csv file, and I tried all the below, which was basically putting the file in different directories (shared drive, then C drive, etc.). I also tried using setwd, but no luck.

我在Windows中使用R。

I am using R in windows.

这是我尝试过的,以及我得到的错误:

Here's what I tried, and the errors I got:

> afl.df=read.csv("afl_2003_2007.csv")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'afl_2003_2007.csv': No such file or directory
> afl.df=read.csv("\\the-lab.llnl.gov\llnlusers1\lopez235\Data\Documents\Dashboards,HRBI, Visulizations and Analytics\Math and Statistics and Predictive Modeling1\R Programming\afl_2003_2007.csv")
Error: '\l' is an unrecognized escape in character string starting "\\the-lab.llnl.gov\l"
> afl.df=read.csv("C:\Users\lopez235\Local-NOTBackedUp\R Files Local\afl_2003_2007.csv")
Error: '\U' used without hex digits in character string starting "C:\U"
> setwd("\\the-lab.llnl.gov\llnlusers1\lopez235\Data\Documents\Dashboards,HRBI, Visulizations and Analytics\Math and Statistics and Predictive Modeling1\R Programming\afl_2003_2007.csv")
Error: '\l' is an unrecognized escape in character string starting "\\the-lab.llnl.gov\l"
> setwd("\\the-lab.llnl.gov\llnlusers1\lopez235\Data\Documents\Dashboards,HRBI, Visulizations and Analytics\Math and Statistics and Predictive Modeling1\R Programming")
Error: '\l' is an unrecognized escape in character string starting "\\the-lab.llnl.gov\l"
> setwd("C:\Users\lopez235\Local-NOTBackedUp\R Files Local")
Error: '\U' used without hex digits in character string starting "C:\U"


推荐答案

使用 / 而不是 \

afl.df=read.csv("C:/Users/lopez235/Local-NOTBackedUp/R Files Local/afl_2003_2007.csv")

这篇关于“字符串中无法识别的转义”在尝试读取CSV文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆