0

I've a link where I need to download data which is in ".iqy" file and I need to read that for further cleaning.

I'm able to do it manually by entering the link present(in 3rd line) in the file using

con <- file("ABC1.iqy", "r", blocking = FALSE) readLines(con=con,n=-1L,ok=TRUE, warn=FALSE,encoding='unknown').

Output:

[1] "WEB"
[2] "1"
[3] "https:abc.../excel/execution/EPnx?view=vrs" [4] ""
[5] ""
[6] "Selection=AllTables"
[7] "Formatting=None"
[8] "PreFormattedTextToColumns=True"
[9] "ConsecutiveDelimitersAsOne=True"
[10] "SingleBlockTextImport=False"
[11] "DisableDateRecognition=False"
[12] "DisableRedirections=False"
[13] ""

I need to automate this instead of doing it manually. Is there any option in r that I can use?

kishore
  • 187
  • 4
  • 14
  • @Moddy_Mudskipper: ya.. :) I just got it right. Also your code works however it pulls it all in a single column like this and so on.
    column1 column2 column3
    – kishore Jun 17 '17 at 08:57

2 Answers2

0

simply use download.file :)

con <- file("ABC1.iqy", "r", blocking = FALSE)
dest_path <- "ABC.file"
download.file(readLines(con=con,n=-1L,ok=TRUE, warn=FALSE,encoding='unknown')[3],destfile= dest_path)

if you can't read the file you get, try :

download.file(readLines(con=con,n=-1L,ok=TRUE, warn=FALSE,encoding='unknown')[3],destfile= dest_path, mode = "wb")
moodymudskipper
  • 46,417
  • 11
  • 121
  • 167
  • `con <- file("ABC1.iqy", "r", blocking = FALSE)` is showing error " Error in file("ABC1.iqy", "r", blocking = FALSE) : cannot open the connection" – kishore Jun 15 '17 at 09:30
0

You can also consider the following approach :

library(RDCOMClient)
library(openxlsx)

xlApp <- COMCreate("Excel.Application")
xlApp[["DisplayAlerts"]] <- FALSE
xlApp[["Visible"]] <- TRUE

path_To_IQY_File <- "D://file.iqy"
path_To_Excel_File <- gsub(pattern = ".iqy", replacement = ".xlsx", x = path_To_IQY_File)

xlWbk <- xlApp$Workbooks()$Open(path_To_IQY_File)
xlWbk$SaveAs(path_To_Excel_File)

df <- openxlsx::read.xlsx(path_To_Excel_File)

I have been able to use this approach for SharePoint lists.

Emmanuel Hamel
  • 1,769
  • 7
  • 19