3

I am using getURLContent(url, userpasswrd, httpauth=1L, binary=TRUE) to download a csv file from a server.

The data I get after using this getURLContent () is a raw vector with contents

"4d" "43" "4e" "2c" "45" "4e"

I know the dataset should have arround 400 columns and few hundred rows. How do I convert this raw vector to into appropriate data. I have used

as.raw(as.hexmode(rawvector1)
rawToChar(iconv(rawvector1, from="UTF-8"))

None of these work. Basically I dont know how to convert raw vector to the right format. Any help here is much appreciated.

Okay I tried this approach and it worked.

test1 = getURLContent(url,userpwd,httpauth = 1L, binary=TRUE) 
testraw1= readBin(test1 , what='characer', n=length(t61)/4) 
new.dataframe = data.frame(read.csv(textConnection(testraw1)))
  • 1
    Can you not just use `read.csv()`? – Rich Scriven Sep 05 '15 at 19:25
  • @RichardScriven, when I try `read.csv` i get an error `Error in read.table(file = file, header = header, sep = sep, quote = quote, : 'file' must be a character string or connection` when I try `read.csv(textConnection(rawvector1))`, i get an error Error in `textConnection(rawvector1) : invalid 'text' argument` – Bridgeport Byron Tucker Sep 05 '15 at 19:34
  • No i meant read.csv directly from the url – Rich Scriven Sep 05 '15 at 19:51
  • @RichardScriven, tried that as well , `read.csv("....\test.csv")` shows `cannot open: HTTP status was '400 Bad Request' error` I tried `readChar(rawVector1, 3)`. I was able to read just the 1st column name "IdN" thats it...there are so 400 columns with varying column name length and data element , looks like UTF-8 encoding issue – Bridgeport Byron Tucker Sep 05 '15 at 19:55
  • 1
    How about `httr`? `GET(url, authenticate(user, passwd), write_disk("file.csv"))` then `read.csv` or no `write_disk()` and use `content(result, as="text")`? – hrbrmstr Sep 05 '15 at 22:33
  • @hrbrmstr, I tried this and it worked , `test1 = getURLContent(url,userpwd,httpauth = 1L, binary=TRUE) testraw1= readBin(test1 , what='characer', n=length(t61)/4) new.dataframe = data.frame(read.csv(textConnection(testraw1)))` – Bridgeport Byron Tucker Sep 05 '15 at 23:43

0 Answers0