5

I'm using plumber as a simple web-api service for some R functions.

I would like to provide a file 'download' (on the client side) through an R function very much like flask is doing it in python through send_file and send_from_directory.

I tried

#* @get /datafile
get_file <- function(){
  return(file('path-to-file.RData'))
}

But unfortunately it didn't work (because the return value cannot be transformed to JSON). I'm aware of static file server option in plubmer, but I really want to provide only one single file and not a directory. (Although serving files in directory through @assets seems to be a more secure option.)

Drey
  • 3,314
  • 2
  • 21
  • 26

1 Answers1

5

Sorry this isn't better documented, but see some examples here: https://github.com/trestletech/plumber/blob/master/tests/testthat/files/includes.R

I don't remember if I've tested with binary data or how it will handle the Rdata content type, so if things are still weird please open a ticket.

Jeff Allen
  • 17,277
  • 8
  • 49
  • 70
  • 1
    yes, thanks, `include_file` works for text type and unfortunately you are right - it does not work with RData. – Drey May 25 '17 at 18:12