2017-08-02 13 views
-1

私のPCのフォルダに複数のHTMLファイルがあります。私はRでそれらを読んで、元のフォーマットをできるだけポーズできるように保ちたいと思います。ちょうどテキストがあります。私は2つのアプローチを試してみました。それは失敗しました:複数のローカルHTMLファイルをR内のフォルダに読み込みます

##first approach 
library (tm) 
cname <- file.path("C:", "Users", "usuario", "Desktop", "DEADataset", "The Phillipines", "gazzetes.presihtml") 
    docs <- Corpus(DirSource(cname)) 
## second approach 
list_files_path<- list.files(path = './gazzetes.presihtml') 
a<- paste0(list_files_path, names) # vector names contain the names of the file with the .HTML extension 
rawHTML <- readLines(a) 

どれでも推測できますか?すべて最高

答えて

1

readLinesは1つの接続しか受け付けませんが、複数のファイルを持つベクターを与えている点を除いて、2番目の方法は機能しています。これを実現するにはlapplyreadLinesを使用できます。ここに例があります:

# generate vector of html files 
files <- c('/path/to/your/html/file1', '/path/to/your/html/file2') 

# readLines for each file and put them in a list 
lineList <- lapply(files, readLines) 

# create a character vector that contains all lines from all files 
lineVector <- unlist(lineList) 

# collapse the character vector into a single string 
html <- paste(lineVector , collapse = '\n') 

# print the string with original formatting 
cat(html) 
+0

ありがとう!私は完全にこれらの事件のために '' lapply''の使用を忘れてしまった。ちょうどレコードのため:私は猫を使用すると、私は "爆弾"(セッションが中止)を取得 –

+0

再:猫の爆弾...おそらく文字列の文字サイズの制限を超えている?私がこれをテストしたとき、私は比較的短い文字列の2つの小さなhtmlファイルを使用しました。 – jdbcode

+0

Heheの猫の爆弾。はい、あなたは正しいです。 –

関連する問題