-1

我想使用 URL 地址作为文件名而不是“i”。认为这是小菜一碟,只是links[i,0]在写函数中而不是“i”,但它似乎不起作用。

library(RCurl) 
library(foreach) 
library(foreign)

links <- read.table("CSV FILE WITH N LINKS", header = T, quote = "\"")

outpath <- "RANDOM FOLDER"

foreach(i = 1:nrow(links)) %do% {
text <- getURL(links[i,])  print(i) 
write(as.character(text), file = paste(outpath, "/", i, ".txt", sep = ""))}

我收到以下错误:

10: In file(file, ifelse(append, "a", "w")) :
  cannot open file '/Users/kasper2304/Desktop/Lego test/Star Wars output/http://news.lugnet.com/starwars/?n=10.txt': No such file or directory
4

1 回答 1

2

:Windows 或 Mac OS 中,不接受作为文件名中的字符。从文件名中删除:字符以解决问题。有人可能会strsplit()为此目的使用。

于 2012-09-10T17:15:52.880 回答