7

I am new to R . I am supposed to expose rest service using R , So i found plumber to expose rest service using R , I Successfully implemented plumber in R , but in response i am receiving a json array like below

[{"name":"Rajesh","age":"10"}]

how to remove the array from the above response

my expected output is like below

{"name":"Rajesh","age":"10"}

Code

 library(plumber)
r <- plumb("MyFile.R")
r$run(port=8000)

My File .R is mentioned below

    #* @post /sum
addTwo <- function(){
  name<-c("Rajesh")
  age<-c("10")
  df<-data.frame(name,age)

  return(df)

}
SymbolixAU
  • 25,502
  • 4
  • 67
  • 139

1 Answers1

1
library(jsonlite)

df <- jsonlite::toJSON(data.frame(name, age, auto_unbox=TRUE))
SymbolixAU
  • 25,502
  • 4
  • 67
  • 139
Eoghan Hynes
  • 41
  • 11