Skip to content

Commit

Permalink
added type casts and show type info
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad1991 committed Nov 4, 2024
1 parent ed43a40 commit 01de61a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
42 changes: 41 additions & 1 deletion bs/R/OperationsModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ OperatorEditorSidebar <- function(id) {
actionButton(NS(id, "c"), "concatenate", class = "add-button"),
class = "boxed-output"
),
div(
h3("Convert types of columns"),
actionButton(NS(id, "as.char"), "convert to character",
title = "Convert a column of the dataset or an intermediate variable to character. For example as.char(ColName)",
class = "add-button"),
actionButton(NS(id, "as.int"), "convert to integer",
title = "Convert a column of the dataset or an intermediate variable to integer. For example as.int(ColName)",
class = "add-button"),
actionButton(NS(id, "as.double"), "convert to real number",
title = "Convert a column of the dataset or an intermediate variable to a real number. For example as.real(ColName)",
class = "add-button"),
class = "boxed-output"
),
div(
h3("Random number functions"),
actionButton(NS(id, "dnorm"), "dnorm", class = "add-button"),
Expand Down Expand Up @@ -235,13 +248,25 @@ OperationEditorServer <- function(id, data) {
r_vals$df_name <- create_df_name(r_vals$df_name, names(data$df))
r_vals$intermediate_vars[[r_vals$df_name]] <- data$df
output$head <- renderUI({
col_info <- sapply(data$df, function(col) class(col)[1]) |>
t() |>
as.data.frame()
names(col_info) <- names(r_vals$df)
div(
class = "var-box-output",
h4("df",
title =
"This is the dataset. Using the text df you can access the entire dataset. If you only want to work with one of the column you can use the respective column title. As a side note only the first 6 rows of the data table are shown.",
class = "var-output"),
renderTable(head(r_vals$df))
div(
title = "This displays the current types for each column",
renderTable({
col_info
})
),
renderTable({
head(r_vals$df)
})
)
})
})
Expand Down Expand Up @@ -670,6 +695,21 @@ OperationEditorServer <- function(id, data) {
updated_text <- paste(current_text, "c(", sep = " ")
updateTextAreaInput(session, "editable_code", value = updated_text)
})
observeEvent(input$as.char, {
current_text <- input$editable_code
updated_text <- paste(current_text, "as.char(", sep = " ")
updateTextAreaInput(session, "editable_code", value = updated_text)
})
observeEvent(input$as.int, {
current_text <- input$editable_code
updated_text <- paste(current_text, "as.int(", sep = " ")
updateTextAreaInput(session, "editable_code", value = updated_text)
})
observeEvent(input$as.real, {
current_text <- input$editable_code
updated_text <- paste(current_text, "as.real(", sep = " ")
updateTextAreaInput(session, "editable_code", value = updated_text)
})
observeEvent(input$dnorm, {
current_text <- input$editable_code
updated_text <- paste(current_text, "dnorm(", sep = " ")
Expand Down
3 changes: 2 additions & 1 deletion bs/R/check_ast.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ allowed_fcts <- function() {
"mean", "sd", "median", "quantile", "range",
"sum", "diff", "min", "max", "scale",
"c", "vector", "length", "matrix", "~",
"get_rows", "get_cols"
"get_rows", "get_cols",
"as.char", "as.int", "as.real"
)
}

Expand Down
12 changes: 12 additions & 0 deletions bs/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,15 @@ create_df_name <- function(current_df_name, column_names) {
}
}
}

as.char <- function(v) {
return(as.character(v))
}

as.int <- function(v) {
return(as.integer(v))
}

as.real <- function(v) {
return(as.numeric(v))
}

0 comments on commit 01de61a

Please sign in to comment.