ropensci / popler

The R package to browse and query the popler database
https://docs.ropensci.org/popler
MIT License
8 stars 7 forks source link

cleaning up extraneous functions in browse() #21

Closed bochocki closed 7 years ago

bochocki commented 7 years ago

There are some functions, in browse() at least, that perform relatively simple tasks and are only used once. We should minimize the use of functions like this to improve code readability and to minimize errors.

bochocki commented 7 years ago

removedtable_select(). code was:

table_select <- function(x, full_tbl = FALSE, possible_args){
  if(full_tbl == FALSE) return(x[,possible_args])
  if(full_tbl == TRUE)  return(x) 
}

changed to:

subset_data <- if(full_tbl){subset_data} else {subset_data[,possible_args()]}

and instead of defining a function, I just use this in a single location in browse()

I also started an "UNUSED FUNCTIONS" section at the bottom of browse.R to track functions that we're removing from the main code without deleting them.

bochocki commented 7 years ago

Changed the function

# changes clss to class and ordr to order
class_order_names <- function(x){
  names(x)   <- gsub("clss","class",names(x))
  names(x)   <- gsub("ordr","order",names(x))
  return(x) 
}

to the more generic

# changes a column name from one name to another
colname_change = function(from, to, x){
  names(x) <- gsub(from,to,names(x))
  return(x)
}

and updated the appropriate lines in main_table(). moved class_order_names() to "UNUSED FUNCTIONS".

bochocki commented 7 years ago

I removed the "Unused Functions" in browse.R

AldoCompagnoni commented 7 years ago

I removed tallies and multiple_columns, which are used in summary_popler instead. Closing this issue, as I believe it requires no peer-review.