R/utils-io.R

Defines functions write_descr_file read_descr_file

#' #' **Open a file in editor**
#' #' 
#' #' @noRd
#' 
#' edit_file <- function(path) {
#'   
#'   if (rstudioapi::isAvailable() && rstudioapi::hasFun("navigateToFile")) {
#'     
#'     rstudioapi::navigateToFile(path)
#'     
#'   } else {
#'     
#'     utils::file.edit(path)  
#'   }
#'   
#'   invisible(NULL)
#' }



#' **Read DESCRIPTION content**
#' 
#' @noRd

read_descr_file <- function() { 
  
  check_for_descr_file()
  
  path <- path_proj()
  
  col_names <- colnames(read.dcf(file.path(path, "DESCRIPTION")))
  
  descr <- read.dcf(file.path(path, "DESCRIPTION"), keep.white = col_names)
  
  if (nrow(descr) != 1) {
    stop("Malformed 'DESCRIPTION' file", call. = FALSE)
  }
  
  as.data.frame(descr, stringsAsFactors = FALSE)
}



#' **Write DESCRIPTION (erase content)**
#' 
#' @noRd

write_descr_file <- function(descr_file) { 
  
  
  check_for_descr_file()
  
  path <- path_proj()
  
  write.dcf(descr_file, file = file.path(path, "DESCRIPTION"), indent = 4, 
            width = 80, keep.white = colnames(descr_file))
  
  invisible(NULL)
}

Try the rdeps package in your browser

Any scripts or data that you put into this service are public.

rdeps documentation built on May 29, 2024, 8:16 a.m.