To return df, simply write return(df):
IMDBmovierating <- function(movie){
link <- paste("http://www.omdbapi.com/?t=", movie, "&y=&plot=short&r=json", sep = "")
jsonData <- fromJSON(link)
df <- data.frame(jsonData)
return(df)
}
or, even simpler in this case, omit the last assignment:
IMDBmovierating <- function(movie){
link <- paste("http://www.omdbapi.com/?t=", movie, "&y=&plot=short&r=json", sep = "")
jsonData <- fromJSON(link)
data.frame(jsonData)
}
If the last expression evaluates to a result object, as data.frame(..) does, then this gets the return object of the enclosing expression and the explicit return statement may be omitted.
edit: and remove the back-ticks before sep and after you closing parenthesis
edit2: Of course MrFlick's comment is correct: the only thing really wrong with your code are the back-ticks that probably are simply a typo here on the site. Even the assignment produces the assigned value as a result object, but it is invisible. Hence, you can assign it, but it is not automatically printed on the console.
data.frame(jsonData)instead ofdf <-data.frame(jsonData)print()that variable, you should be able to see the result. eg:f<-function(a) {b<-a+1}; x<-f(4); print(x)x <- 1; x,x <- 1or(x <- 1). And what about=operator.<-and=will behave identically, they both perform assignment. Whey you run an assignment expression, it will return invisibly. But when you runxor use()both of those are separate expressions so the invisible part will not apply and you'll see the value. If you need more details, it would probably be best to open your own new question.