-1

when i loading csv file for R, i can see the error but i don't know why this happening

i wrote following code:

setwd("C:\\Users\\규남\\Desktop\\twitter")
library(KoNLP)
useSejongDic()
txt <- readLines(file("test.csv"))

and, this error appear

txt <- readLines(file("test.csv"))
Error in readLines(file("test.csv")) : cannot open the connection
In addition: Warning message:
In readLines(file("test.csv")) :
  cannot open file 'test.csv': No such file or directory

why this happening? file directory is not wrong, and that file in the folder [enter image description here][1] please see this i restart Rstudio, even notebook power but error appear again how to i load that csv file? and why this happening? here is result useing getwd() function

[1] "C:/Users/규남/Desktop/twitter"
Warning message:
closing unused connection 3 (test.csv) 

[1]: https://i.stack.imgur.com/xkFkt.png
Sotos
  • 51,121
  • 6
  • 32
  • 66
L.kyunam
  • 53
  • 12
  • `\ ` has a special meaning. Try using `/` instead in `setwd()` – Richard Telford Apr 20 '16 at 14:27
  • same error appear in console – L.kyunam Apr 20 '16 at 14:30
  • Is your file listed when you run `dir()`? – Richard Telford Apr 20 '16 at 14:41
  • what's mean dir()? you mean that i open that file,at the same time, i run that coding? – L.kyunam Apr 20 '16 at 14:44
  • `dir()` shows the files in the working directory. Most likely, your working directory is not what you expect, or you are mistyping the file name. `file.choose()` can be very useful. – Richard Telford Apr 20 '16 at 14:46
  • following your suggestion, i write code like this : "txt <-readLines(file(file.choose()))" and i choose file that i want load csv file. but this error appear Warning messages: 1: closing unused connection 4 (test.csv) 2: closing unused connection 3 (test.csv) i don't know why this happening should i try to delect R and R studio and reset program? – L.kyunam Apr 20 '16 at 14:50
  • 1
    did it work? better to use `myfile <- file.choose()` then `readLines(myfile)` ie delete the `file()` – Richard Telford Apr 20 '16 at 14:56
  • perfact!! thank you very much! how to i vote you? when i tried this code, "txt <-readLines(file(file.choose()))" can work but still exist error i think that code cause error. but your suggestion can be work no error and load perfact! thank you very much. you save my life! – L.kyunam Apr 20 '16 at 15:03

1 Answers1

0

When working through these problems I like to use the file.path() function. Look at the documentation, but it makes certain that the separator characters that are used in the string are what R is expecting.

Try:

path <- file.path("C:", "Users", "규남", "Desktop", "twitter")
setwd(path)
library(KoNLP)
useSejongDic()
txt <- readLines(file("test.csv"))
Richard Lusch
  • 1,050
  • 10
  • 19
  • this way still view same error. i didn't know why this happening. but following your reply suggestion, using 'file.choose()' function, the error disappear! – L.kyunam Apr 20 '16 at 15:08
  • may be....korean laguage using in file directory '규남', so this happening appear i think. – L.kyunam Apr 20 '16 at 15:12