the curl command behaves differently on mac and windows

1. system() with curl -o option

After noting that curl on Windows requires the https address to be enclosed within double- instead of single-quotes, I would avoid the remaining piping issue altogether and use the -o option in curl to specify a file to write results to if you insist on writing the command out:

system(paste0("curl -k -X GET \"https://ldlink.nci.nih.gov/LDlinkRest/ldproxy?var=", SNPs.needproxies[i], "&pop=MXL&r2_d=r2&token=", token, "\" -o out.", SNPs.needproxies[i], ".txt"))

2. curl_download()

Alternatively, R has a few curl-based packages that take care of all of these details such as curl:

library(curl)
url <- sprintf("https://ldlink.nci.nih.gov/LDlinkRest/ldproxy?var=%s&pop=MXL&r2_d=r2&token=%s", SNPs.needproxies[i], token)
curl_download(url, sprintf("out.%s.txt", SNPs.needproxies[i]))

3. file.download()

You might also just use file.download() in this case as Konrad suggested:

url <- sprintf("https://ldlink.nci.nih.gov/LDlinkRest/ldproxy?var=%s&pop=MXL&r2_d=r2&token=%s", SNPs.needproxies[i], token)
download.file(url, sprintf("out.%s.txt", SNPs.needproxies[i]))

4. GET()

You could also use GET() in from the httr library:

library(httr)
u <- "https://ldlink.nci.nih.gov/LDlinkRest/ldproxy"
q <- list(var = SNPs.needproxies[i],
          pop = "MXL",
          r2_d = "r2",
          token = token)
f <- sprintf("out.%s.txt", SNPs.needproxies[i])
GET(url = u, query = q, write_disk(f))

5. LDproxy()

Note, there appears to be an R package specifically for connecting to this API here. In your case the code would be:

library(LDlinkR)
LDproxy(snp = SNPs.needproxies[i],
        pop = "MXL", 
        r2d = "r2", 
        token = token, 
        file = sprintf("out.%s.txt", SNPs.needproxies[i]))

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top