Checking filenames in upload in R Shiny

...
Good afternoon. I want to check in R shiny after uploading 2 files if one part of the filename is identical or not. I have done this

data <- reactive({
    inFile=input$bam
    #str(inFile)
    clean_file_1=str_extract_all(inFile, regex("[0-9]{3}[:punct:][0-9]{5}[:punct:][A-Z]{3}[0-9]{8}"))[[1]]
    clean_file_2=str_extract_all(inFile, regex("[0-9]{3}[:punct:][0-9]{5}[:punct:][A-Z]{3}[0-9]{8}"))[[2]]
    #a = clean_file_1 == clean_file_2
    
    if (clean_file_1 == clean_file_2){
      return(inFile)
    } else {
      print("Error message by Adam")
    }
    #validate(need(clean_file_1 == clean_file_2, print("Please upload the same Dna number pool1+pool2"))
    
    
    
  })

Regex and comparison are correct when I checked out of shiny. The error message in Shiny is the following

Warning: Error in if: the argument is of length zero

When I try with validate does not accept the comparison symbol

The target is that if the 2 uploaded files have a small part of filenames identical to proceed the app if are not to prompt an error message suggesting to the user to be careful of what files he uploaded. Thank you

this is a common message to see that often happens when we are trying to compare two objects within an if() but one of the objects is NULL, the result of the comparison == will therefore not be TRUE nor FALSE but rather logical(0) which has no length).

#what is probably happening for you
a <- 1
b <- NULL
if(a == b){
  print("a == b")
}

#guard against it
library(shiny)
if(isTruthy(a) & isTruthy(b)){
  if(a == b){
    print("a == b")
  }
} else {
  print("skipping as one of a or b is empty")
}

Hi and thank you very much.
Yes is very related with what you answered me.

data <- reactive({
    #Input of two files
    inFile<-input$bam
    #Extracting one part of the filename 
    clean_file_1=str_extract_all(inFile, regex("[0-9]{3}[:punct:][0-9]{5}[:punct:][A-Z]{3}[0-9]{8}"))[[1]]
    clean_file_2=str_extract_all(inFile, regex("[0-9]{3}[:punct:][0-9]{5}[:punct:][A-Z]{3}[0-9]{8}"))[[2]]
    #Filtering if that part is identical and return the filenames to proceed as data() in other parts
    if(isTruthy(clean_file_1) & isTruthy(clean_file_2)){
      if(clean_file_1 == clean_file_2){
            inFile
    
        
      }
    } else {
        #If not identical I would receive the message wrong files or whatever.
           print("Wrong Files")
    }

The issue still remains. Does not "read" the comparison and extracting directly the else statement. ( I try to swap the print with inFile)

maybe the issue is at clean_file_1 and clean_file_2....in simple R reading and extracting correct results....
Maybe exists other way to filter the filenames....I appreciate any help please

you should give an indication what the content of input$bam i,e, inFile might be.
perhaps change your code to

inFile <<- input$bam

that way when you exit out of the application, inFile will persist as a Global variable that you can investigate/share.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.