-1

I'm using a Rest API to GET a model (.rda) file. I'm trying to load the file/model in-memory since I have the binary object (obtained successfully), but I'm finding this rather difficult. I'd include some sample code, but to be honest I'm struggling to make an attempt. The load() documentation notes that it can take "a (readable binary-mode) connection", so my attempts have involved trying these out with no success. I always struggle with these I/O tasks so any help would be very appreciated.

ricniet
  • 115
  • 6
  • 2
    It's not clear how you are making the API request currently. What exactly is the code you've tried? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. You'll likely need to do two steps. First, transfer it to your computer, then secondly, load the file. – MrFlick Oct 11 '21 at 22:06
  • It was more of a general question about how to handle streaming binary data. I didn't include info about the request because I'm describing what the contents were. In any case, I've figured it out and will post. – ricniet Oct 11 '21 at 22:59

1 Answers1

2

Here's how I was able to load an .rda model in one step:

endpoint <- 'v2/asset_files/data_asset/sample_model.rda'
r = httr::GET(url = paste(DATA_API_URL,endpoint,sep='/'),
              query = list(project_id = project_id))

# class(r$content) is raw
load(rawConnection(r$content))
ricniet
  • 115
  • 6