0

I am trying and failing to use RCurl to automate the process of fetching a spreadsheet from a web site, China Labour Bulletin's Strike Map.

Here is the URL for the spreadsheet with the options set as I'd like them:

http://strikemap.clb.org.hk/strikes/api.v4/export?FromYear=2011&FromMonth=1&ToYear=2015&ToMonth=6&_lang=en

Here is the code I'm using:

library(RCurl)
temp <- tempfile()
temp <- getForm("http://strikemap.clb.org.hk/strikes/api.v4/export",
  FromYear="2011", FromMonth="1", 
  ToYear="2015", ToMonth="6",
  _lang="en")

And here is the error message I get in response:

Error: unexpected input in:
"     ToYear=2015, ToMonth=6,
     _"

Any suggestions on how to get this to work?

ulfelder
  • 5,305
  • 1
  • 22
  • 40
  • getForm("http://strikemap.clb.org.hk/strikes/api.v4/export",.params = list( ToYear="2015",ToMonth="6",FromYear="2011", FromMonth="1")) this works but I don't know how and why I was not able to add _lang in the parameter – The6thSense Jun 04 '15 at 13:39

1 Answers1

2

Try enclosing _lang with a backtick.

temp <- getForm("http://strikemap.clb.org.hk/strikes/api.v4/export",
                FromYear="2011",
                FromMonth="1",
                ToYear="2015",
                ToMonth="6",
                `_lang`="en")

I think R has trouble on the argument starting with an underscore. This seems to have worked for me.

TARehman
  • 6,659
  • 3
  • 33
  • 60
  • Thank you! I figured it was the underscore and didn't know how to escape it. Of course, now I can't read the temp file into workable form. Here's what I'm trying: `library(readxl)` `CLB <- read_excel(temp)` And here's what I'm getting: `Error in file.exists(path) : invalid 'file' argument` Any suggestions on that would be much appreciated. – ulfelder Jun 05 '15 at 14:00
  • You should ask another question for your new issue, rather than adding it in a comment. – TARehman Jun 05 '15 at 14:40
  • I replied because I thought it might be a residual issue from the first process instead of a new one, but I appreciate your advice and will follow it. Thanks again. – ulfelder Jun 05 '15 at 15:37
  • No problem. :) You'll get a better response with a new question and it's in line with how the site is designed to work - separate questions for separate issues. SO is all about asking good questions and getting good answers. If you ping me in the comment here I can always try and look at that one too. – TARehman Jun 05 '15 at 15:38
  • Follow-up question finally posted [here](http://stackoverflow.com/questions/31220677/invalid-path-argument-with-xlconnect). – ulfelder Jul 04 '15 at 13:18