File path issues in R using Windows (“Hex digits in character string” error)

前端 未结 11 2084
我寻月下人不归
我寻月下人不归 2020-11-28 19:06

I run R on Windows, and have a csv file on the Desktop. I load it as follows,

x<-read.csv(\"C:\\Users\\surfcat\\Desktop\\2006_dissimilarity.csv\",header=T         


        
11条回答
  •  伪装坚强ぢ
    2020-11-28 19:42

    I know this is really old, but if you are copying and pasting anyway, you can just use:

    read.csv(readClipboard())
    

    readClipboard() escapes the back-slashes for you. Just remember to make sure the ".csv" is included in your copy, perhaps with this:

    read.csv(paste0(readClipboard(),'.csv'))
    

    And if you really want to minimize your typing you can use some functions:

    setWD <- function(){
      setwd(readClipboard())
    }
    
    
    readCSV <- function(){
      return(readr::read_csv(paste0(readClipboard(),'.csv')))
    } 
    
    #copy directory path
    setWD()
    
    #copy file name
    df <- readCSV()
    

提交回复
热议问题