req() in R 4.0.1

I made an application on version R 3.6.3 that works quite well.
While upgrading to R 4.0.1, I encountered a problem. The error "error evaluating the 'x' argument when selecting a method for the 'reducedDimsNames' function" appeared in the graphics where an input was not yet selected.

Here is an example (Shiny reprex) of code that shows me the error on version R 4.0.1 but not on version 3.6.3. (I hope this is a shiny reprex. It is in any case a simplification of my application which meets several times this problem)

## free SingleCellExperiment object
# library(scRNAseq)
# library(scater)
# library(SingleCellExperiment)
# sce <- LaMannoBrainData('mouse-adult')
# sce <- runPCA(sce,ncomponents=10,exprs_values="counts")
# reducedDimNames(sce)
# save(sce,file="SCEex.RData")

## Only run this example in interactive R sessions
if (interactive()) {
    ui <- navbarPage("NOM APPLI",
                     
                     
                     # Onglet - data Import
                     tabPanel("Upload Data",
                              sidebarLayout(
                                  sidebarPanel(
                                      fileInput("fileData",label = "Choose the RData file containing the SCE object:"), 
                                      uiOutput("redDimInput"),
                                      uiOutput("dimRed"), 
                                      actionButton("go_button_viz", "GO")
                                  ),
                                  mainPanel(
                                      verbatimTextOutput("idout")
                                  )))
            
    )
    
    server <- function(input, output) {
        object <- reactive({
            # if (is.null(req(input$fileData))){return(NULL)}
            inFile <- req(input$fileData)
            file <- inFile$datapath
            # load the file into new environment and get it from there
            e = new.env()
            name <- load(file, envir = e)
            # name = nom des objets importes et on load les objets sur e
            object <- e[[name]]
            
            # return(list(object = object, name=name, file=inFile))
            return(object)
        })
        
        output$redDimInput <- renderUI(selectInput("redDim",
                                                   "Choose the coordinates of dimension reduction",
                                                   choices=reducedDimNames(req(object()))))
        
        
        
        output$idout <- renderPrint({
            reducedDim(object(), type=input$redDim)
        })
    }
 
    shinyApp(ui, server)
}

I think the error comes from the req() function which would not execute properly. But I probably don't know how to use it properly.

Thanks for your help,

Nicolas

Thanks for your helpful reprex!

Just adding req(object()) to the top of your output$redDimInput and output$idout calls fixed the error evaluating the 'x' argument when selecting a method for the 'reducedDimsNames' function error on my end, R 4.0.1.

I think it's just that you were passing NULL to the reducedDimsNames/reducedDim functions. Maybe your object() function returns NULL now when it hits a req-->FALSE, so you need to req that for the outputs.

## free SingleCellExperiment object
library(scRNAseq)
library(scater)
library(SingleCellExperiment)
library(shiny)
# sce <- LaMannoBrainData('mouse-adult')
# sce <- runPCA(sce,ncomponents=10,exprs_values="counts")
# reducedDimNames(sce)
# save(sce,file="SCEex.RData")

## Only run this example in interactive R sessions
if (interactive()) {
  ui <- navbarPage(
    "NOM APPLI",


    # Onglet - data Import
    tabPanel(
      "Upload Data",
      sidebarLayout(
        sidebarPanel(
          fileInput("fileData", label = "Choose the RData file containing the SCE object:"),
          uiOutput("redDimInput"),
          uiOutput("dimRed"),
          actionButton("go_button_viz", "GO")
        ),
        mainPanel(
          verbatimTextOutput("idout")
        )
      )
    )
  )

  server <- function(input, output) {
    object <- reactive({
      # if (is.null(req(input$fileData))){return(NULL)}
      inFile <- req(input$fileData)
      file <- inFile$datapath
      # load the file into new environment and get it from there
      e <- new.env()
      name <- load(file, envir = e)
      # name = nom des objets importes et on load les objets sur e
      object <- e[[name]]

      # return(list(object = object, name=name, file=inFile))
      return(object)
    })

    output$redDimInput <- renderUI({
      object <- req(object())
      selectInput("redDim",
        "Choose the coordinates of dimension reduction",
        choices = reducedDimNames(object)
      )
    })



    output$idout <- renderPrint({
      object <- req(object())
      reducedDim(object, type = input$redDim)
    })
  }

  shinyApp(ui, server)
}

P.S.:
In the future, you might be able to get more help if you can cut out those Bioconductor packages--those took a long time to install on my end and I'm not sure they were completely necessary to recreate the problem. Still, it was great to have some code to work with :slight_smile:


History:

I ran your example (after installing those dependencies) on R 4.0.0.

When I uploaded your example SCEex.RData file, I was given a different error:

Warning: Error in : unable to find an inherited method for function ‘reducedDim’ for signature ‘"SingleCellExperiment", "NULL"’
[No stack trace available]

From my end, it looks like the req() line works just fine:

EDIT: But, after updating to 4.0.1, I do get the same error as OP, so that's kinda fun. And the debug places it right at the req() line. Adding solution at top.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.