<label>Data menu: <i id='help_data_all' title='Check all' href='#' class='action-button glyphicon glyphicon-ok'></i>
              <i id='help_data_none' title='Uncheck all' href='#' class='action-button glyphicon glyphicon-remove'></i></label>

## get the active dataset and show the first few observations
.getdata() %>% head

## access a specific dataset by name
r_data[['diamonds']] %>% select(price, clarity) %>% head

## add a variable to the diamonds data
dat <- r_data[['diamonds']]
dat$log_price <- log(dat$price)

## show the first observations
dat %>% select(price, log_price) %>% head

## create a histogram of prices
dat %>% ggplot(aes(x = price)) + geom_histogram()

## and a histogram of log-prices using radiant.data::visualize
dat %>% visualize(xvar = "log_price", custom = TRUE)


## open help in the R-studio viewer from Radiant
help(package = 'radiant')

## If you are familiar with Shiny you can call reactives when the code
## is evaluated inside a Shiny app. For example, if you transformed
## some variables in Data > Transform you can call the transform_main
## reacive to see the latest result. Very useful for debugging
# transform_main() %>% head

## Report on diamond prices

Test the hypothesis that the average price of diamonds in the available data is larger than $4500 after filtering out the cheapest diamonds (< $1000)

```{r fig.width=7, fig.height=8.62}
result <- single_mean(dataset = "diamonds", var = "price", comp_value = 4500, alternative = "greater", data_filter = "price > 1000")
summary(result)
plot(result, plots = c("hist", "simulate"))
```

Compare diamond prices by the quality of the 'cut'. It seems that diamonds with a premium cut cost more than diamonds with a ideal cut. Seems strange. Perhaps we should use regression to control for the carats of the diamond. Try it!

```{r fig.width=7, fig.height=8.62}
result <- compare_means(dataset = "diamonds", var1 = "cut", var2 = "price", alternative = "greater", data_filter = "price > 1000")
summary(result)
plot(result, plots = c("bar", "density"))
```

Visualize the relationship between diamond prices, carats, and the cut of the diamond.

```{r fig.width=6.46, fig.height=8.4}
visualize(dataset = "diamonds", xvar = "carat", yvar = "price", type = "scatter", facet_row = "cut", color = "cut", data_filter = "price > 1000")
```