[英]dplyr: Downloading a file based on the values in every row of a data_frame
I am trying to download a file based on the values in the rows of a data_frame
. 我正在尝试根据data_frame
行中的值下载文件。 Here is what the data_frame
looks like: 这是data_frame
样子:
df_foo = data_frame(
input_id = 1:10,
file_name_id = 20:30
)
Here is an attempt using by_row
from the purrr
package which does not work. 这是尝试从purrr
包中使用by_row
的尝试,但无效。
df_foo %>%
by_row(
.f = download.file,
url = paste0("http://foobar.com/id=", input_id),
destfile = paste0("file number", file_name_id, ".txt")
)
I have also tried invoke_rows
( map_rows
). 我也尝试了invoke_rows
( map_rows
)。 Any solution that would work in pipes would be appreciated. 任何将在管道中工作的解决方案将不胜感激。
With rowwise
: 与rowwise
:
df_foo %>%
rowwise %>%
do(f=download.file(paste0("http://example.com/id=", .$input_id),
paste0("file_", .$filename_id)))
But do you really need dplyr? 但是,您真的需要dplyr吗?
mapply(download.file, paste0("http://example.com/id=", df_foo$input_id),
paste0("file_", df_foo$filename_id))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.