BirdScanCommunity / birdscanR

3 stars 2 forks source link

classAbbrevation.rda have empty space #43

Closed baptischmi closed 4 months ago

baptischmi commented 4 months ago

Selection of classes in package-data 'classAbbrevation.rds' isn't working becasue of empty space, e.g. wader_type

classSelection = c("passerine_type", "wader_type", "swift_type", "large_bird", "unid_bird", "bird_flock", "insect")# , "nonbio", "precipitation"

classAbbreviations$class

classAbbreviations$class [1] "passerine_type" "wader_type " "swift_type " "large_bird" "unid_bird "
[6] "bird_flock" "insect " "nonbio " "precipitation"

classAbbreviations$class %in% classSelection

classAbbreviations$class %in% classSelection [1] TRUE FALSE FALSE TRUE FALSE TRUE FALSE FALSE FALSE

baptischmi commented 4 months ago

In the function savePlotToFile, the option to use the data classAbbreviation has been outcommented. for what reason?

# classSelection for fileName
# =========================================================================
  if (!is.null(classSelection)){
    # classes = paste(classAbbreviations$abbr[match(classSelection, 
    #                                                classAbbreviations$class)], 
    #                  collapse = "")
    fileName = paste(fileName, classSelection, sep = "_")
  } else {
    fileName = paste(fileName, "allClasses", sep = "_")
  }
baptischmi commented 4 months ago

a work around would be the addition of this line: classAbbreviations$class <- trimws(classAbbreviations$class, which = "right")

BirgenH commented 4 months ago

In the function savePlotToFile, the option to use the data classAbbreviation has been outcommented. for what reason?

# classSelection for fileName
# =========================================================================
  if (!is.null(classSelection)){
    # classes = paste(classAbbreviations$abbr[match(classSelection, 
    #                                                classAbbreviations$class)], 
    #                  collapse = "")
    fileName = paste(fileName, classSelection, sep = "_")
  } else {
    fileName = paste(fileName, "allClasses", sep = "_")
  }

You can control this directly with the input parameter 'classSelection' of the savePlotToFile() function, i.e., you can simply pass them as the string you want, and they become part of the plot filename. So if you want abbreviations, you can create the abbreviations in your main script prior to passing them to the 'classSelection' input parameter of the function.

I updated the classAbbreviations.rda file of the package so it doesn't contain any whitespaces anymore. Thanks for catching it!