mannym mannym - 1 year ago 75
R Question

passing through special characters in password when using download.file

I am trying to download a file using the

function. The URL I am using is password protected. My password however has multiple special characters in it and it is not letting me download my file. Is there a way I can bypass this without changing the password?

The password I am using includes the special characters '$' '@'

Below is the example and the error code I am getting.

download.file("http://myusername:P@$$$format=json", myfile.json, method = "auto")

'InternetOpenUrl failed: 'The server name or address could not be resolved'

Answer Source

Try encoding the characters in your password:

password <- "P@$$sword"
password <- URLencode(password, reserved=TRUE)  # deal with @ and $

file.loc <- sprintf("", password)
download.file(file.loc, ...)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download