2
I have a list of links that automatically download pdf files and would like to save them with a new name in a folder that I created with dir.create().
I thought of originally importing the file as an R object but the pdf is not available online, just for download. I also could not change the download settings with the download.file().
A piece of my code:
i <- "/consulta/dowload-arquivo-anexado/id/1229" 
#isso aqui vai ser um loop futuramente, por isso esse i
#url do documento
url2 <- paste0("http://oportunidades.mda.gov.br" , i)
#criando diretório que eu irei salvar meu documento
pasta <- gsub('.*/ ?(\\w+)', '\\1', i)
dir.create(paste0(dir_base, pasta))
destino <- paste0(dir_base, pasta)
#o que não deu certo   
download.file(url= url2,
              destfile= destino)
[1]Error in download.file(url = url2, destfile = destino) : cannot open destfile '.Documents/1229', reason 'Permission denied'
Thanks for your help!
the problem pointed out by R is the permission of the folder ". Documents", are you sure this is the folder you want to save the file in? (with the
.beforeDocuments)– Tomás Barcellos
Provide the content of
dir_basecan help.– Tomás Barcellos
I ended up deleting the part I create dir_bases. It is dir_base <- "C:/Users/coliv/Documents/" only a base folder to create the other directories.
– Jessica Voigt
i changed the text of the document folder just to make it cleaner. It points to a folder that actually exists.
– Jessica Voigt
And the mistake remains the same?
– Tomás Barcellos
yes, the error remains the same
– Jessica Voigt
Tries to redefine the
destinobefore. Thusdestino <- paste0(dir_base, pasta, "download.pdf"). And then run the download line again– Tomás Barcellos
@Tomásbarcellos worked! In addition I also needed to enter the method = "Curl" parameter. Thank you very much!!
– Jessica Voigt