Skip to content

Commit

Permalink
lint transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikSchultheis committed Jun 28, 2018
1 parent b6e4302 commit f938bad
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions R/transformation.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ transformationUI <- function(id, label = "Transformation", selected = "raw", cho

ret <- list(
shiny::tags$b(label),
#shiny::actionLink(ns("help"), label = NULL, icon = shiny::icon("question-circle")), # removed for now
# shiny::actionLink(ns("help"), label = NULL, icon = shiny::icon("question-circle")), # removed for now
shiny::selectInput(ns("transform"),
label = NULL,
choices = choices,
selected = selected,
multiple = F))
if(transposeOptions){
if (transposeOptions) {
ret <- list(ret, shinyjs::useShinyjs(), shiny::radioButtons(ns("transpose"), label = NULL, choices = c(`row-wise` = "row", `column-wise` = "column")))
}

Expand All @@ -49,20 +49,20 @@ transformationUI <- function(id, label = "Transformation", selected = "raw", cho
#'
#' @export
transformation <- function(input, output, session, data, transpose = FALSE, pseudocount = 1, replaceInf = TRUE, replaceNA = TRUE) {
#handle reactive data
data.r <- shiny::reactive({
if(shiny::is.reactive(data)){
# handle reactive data
data_r <- shiny::reactive({
if (shiny::is.reactive(data)) {
data()
}else{
} else {
data
}
})

#reset
# reset
shinyjs::reset("transform")
shinyjs::reset("transpose")

#helptext
# helptext
# shiny::observeEvent(input$help, {
# title <- "Data transformation"
# content <- shiny::HTML("Choose a method with which the given data is transformed:<br/>")
Expand Down Expand Up @@ -109,13 +109,13 @@ transformation <- function(input, output, session, data, transpose = FALSE, pseu
}

transformed_data <- shiny::reactive({
data <- data.r()
data <- data_r()

if(transpose | ifelse(!is.null(input$transpose), input$transpose == "row", FALSE) & input$transform == "zscore"){
if (transpose | ifelse(!is.null(input$transpose), input$transpose == "row", FALSE) & input$transform == "zscore") {
data <- t(data)
}

#transform data
# transform data
output <- switch(input$transform,
log2 = log2(data + pseudocount),
`-log2` = -log2(data + pseudocount),
Expand All @@ -126,32 +126,32 @@ transformation <- function(input, output, session, data, transpose = FALSE, pseu
raw = data
)

#replace infinite with NA & NA with 0
if(replaceInf){
# replace infinite with NA & NA with 0
if (replaceInf) {
is.na(output) <- sapply(output, is.infinite)
}
if(replaceNA){
if (replaceNA) {
output[is.na(output)] <- 0
}

if(transpose | ifelse(!is.null(input$transpose), input$transpose == "row", FALSE) & input$transform == "zscore"){
if (transpose | ifelse(!is.null(input$transpose), input$transpose == "row", FALSE) & input$transform == "zscore") {
output <- t(output)
}

return(output)
})

#enable transposeOptions only if relevant
# enable transposeOptions only if relevant
shiny::observe({
if(input$transform == "zscore"){
if (input$transform == "zscore") {
shinyjs::enable("transpose")
}else{
} else {
shinyjs::disable("transpose")
}
})

method <- shiny::reactive({
if(input$transform == "zscore") {
if (input$transform == "zscore") {
paste(input$transform, input$transpose)
} else {
input$transform
Expand Down

0 comments on commit f938bad

Please sign in to comment.