R/getData.R

Defines functions getData

Documented in getData

#' Find data
#'
#' @return
#' @export
#'
#'
getData <- function() {

  again <- TRUE

  while(again) {

    again <- FALSE

    found <- FALSE

    object <- objects(pos = .GlobalEnv)[unlist(lapply(objects(pos = .GlobalEnv), FUN = function(x) {!is.function(eval(parse(text = x)))}))]

    if(length(object) <= 1) {
      stop("There's literally nothing.")
    }


    again <- FALSE

    found <- FALSE


    while(!found) {

      #Initial list of objects
      if(length(object) > 1) {

        first <- TRUE

        x <- 0

        printn(object)
        while(!x %in% 1:length(object)) {
          x <- as.numeric(readline("Choose an entry by number: "))
        }
        object <- object[x]
      }


      #Investigating object
      else if(length(object) == 1) {

        #If list
        if(class(eval(parse(text = object)))[1] == "list") {


          if(length(eval(parse(text = object))) == 0) {

            again <- TRUE

            found <- TRUE

          }

          else if(first) {

            first <- FALSE

            message("List entries: ")
            printn(names(eval(parse(text = object))))

            x <- 0

            while(!x %in% 1:length(eval(parse(text = object)))) {
              x <- as.numeric(readline("Choose list entry by number: "))
            }

            object <- paste(object, "[[", x, "]]", sep = "")

          }

          else {

            message("List entries: ")
            printn(names(eval(parse(text = object))))

            if(whatToDo("Enter or return list?", "enter", "return") == "enter") {

              x <- 0

              while(!x %in% 1:length(eval(parse(text = object)))) {
                x <- as.numeric(readline("Choose list entry by number: "))
              }

              object <- paste(object, "[[", x, "]]", sep = "")

            }

            else {

              return <- eval(parse(text = object))

              found <- TRUE

            }

          }

        }

        #If any data type but a list
        else {


          if(ok(paste0("Return ", class(eval(parse(text = object))), "?"))) {

            return <- eval(parse(text = object))

            found <- TRUE

          }

          else {

            again <- TRUE

            found <- TRUE

          }

        }

      }

    }

  }

  return

}
nicohuttmann/htmnanalysis documentation built on Dec. 6, 2020, 3:02 a.m.