相关疑难解决方法(0)

文件路径中正斜杠(/)和反斜杠(\)之间的差异

我想知道文件路径\和/文件路径之间的区别.我注意到有时路径包含/,有时它与之相关\.

如果有人能解释何时使用\和,那将是很好的/.

c# path slash filepath backslash

145
推荐指数
7
解决办法
5万
查看次数

尝试读取CSV文件时"字符串中无法识别的转义"

我正在尝试导入一个.csv文件,以便我可以跟随这个视频:R ggplot2图形直方图.

我安装了所有适当的包,包括ggplot相关的包.视频中的第一条指令表示要键入afl.df=read.csv("afl_2003_2007.csv")

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

我在Windows中使用R.

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

> 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 …
Run Code Online (Sandbox Code Playgroud)

import r

9
推荐指数
1
解决办法
2万
查看次数

在R中的字符串或路径中转义\

Windows复制\R不接受的路径.所以,我想编写一个将'\'转换为'/'的函数.例如:

chartr0 <- function(foo) chartr('\','\\/',foo)
Run Code Online (Sandbox Code Playgroud)

然后使用chartr0...

source(chartr0('E:\RStuff\test.r'))
Run Code Online (Sandbox Code Playgroud)

但是chartr0没有用.我猜,我无法逃脱'/'.我想逃避/在许多其他场合可能很重要.

另外,在R中是否存在这样的方式,我不必chartr0每次都使用,而是通过在R中创建一个environemnt来自动转换所有路径,它调用chartr0或使用某种临时用法,如使用options

r escaping

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

r ×2

backslash ×1

c# ×1

escaping ×1

filepath ×1

import ×1

path ×1

slash ×1