R/pbiListAllUserGroups.R

Defines functions pbiListAllUserGroups

Documented in pbiListAllUserGroups

#' List all imported files.
#' @description Return a data frame containing information about the groups associated with the user.
#' @param toDf When TRUE, a tabular format is returned. When FALSE, more detailed content is returned as JSON.
#' @return Data frame.
#' @examples
#' \dontrun{pbiListAllUserGroups()}

pbiListAllUserGroups <- function(toDf = TRUE){

  # Call the query builder to make the call.
  l = pbiQueryBuilder(endpoint = "groups")

  # Error handling.
  if(exists("error", where = l)) {
    stop(paste("GET request produced an error message: ", l$error$message))
    return(NULL)
  }

  # If the user wants the JSON from the successful API call, then return it.
  # Don't bother parsing to a data frame.
  if(toDf == FALSE) return(l)

  # Else, parse to a data frame.
  df = data.frame(
    Id = sapply(l$value, function(x){x$id}),
    Name = sapply(l$value, function(x){x$name})
  )

  return(df)

}
olfrost/poweRbi documentation built on May 6, 2019, 6:05 p.m.