私のコードでは、テキストファイルのフォルダを読み込んでdtmに変換するのが難しいです。問題は何らかの理由で、私のコンピュータが間違いなくディレクトリ内のテキストファイルとの接続しか確立できないということです。返すエラーがされています。しかし、私は簡単に任意のテキストエディタで、だけでなく、Pythonでこれらのファイルを開くことができディレクトリから複数のファイルを読むR
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file '[file name]': No such file or directory
。なぜ私は接続を確立することができ、他のものではないかもしれないという考えはありますか?私のコードは以下の通りです:
files <- as.character(list.files(path="[file path]"))
readLines(files[1]) #here is where the error occurs, for example
n <- length(files) #this is my loop
subtitles <- character(n)
subtitle <- character(1)
for (i in 1:n){
subtitle <- as.character(readLines(files[i]))
subtitle <- iconv(subtitle, to="UTF8")
subtitle <- tolower(subtitle)
subtitle <- as.character(paste(subtitle, collapse=" "))
subtitles[i] <- subtitle[1]
}
かだけがfull.names =は 'true'と' list.files'を使用してみてください。 – flodel
よろしくお願いします。ありがとう。これは単なる作業ディレクトリの問題です。時間の無駄に申し訳ありません! – brianabelson