Error : unexpected symbol

Entering a command from an R MArkdown file -

{r load-data} data(nycflights)

And this is what I get, why so?-

Error: unexpected symbol in "{r load"

The equivalent in r console would be

data(nycflights)

Rmarkdown is its own language that R console won't interpret. R Markdown has extra syntax with triple backticks and curly braces to label blocks.

If you want this code to run in an R Markdown file (.Rmd) you need:

```{r load-data}
data(nycflights)
```

If you want to run this code in an R Script file (.R) or in the Console, you'd write just:

data(nycflights)