R/depreciated/open_file.R

Defines functions open_file

#' Quickly open some documents.

#' @author Jiaxiang Li
#'
#' @import rstudioapi
#' @importFrom stringr str_subset
#' @import purrr
#' @import tibble
#' @importFrom dplyr filter
#' @export

open_file <- function(){
    if_open <- function(x){
        if (file.exists(x)) {
            rstudioapi::navigateToFile(x)
        }
    }
    a_rmd <-
        list.files() %>%
        stringr::str_subset("a\\d+\\.Rmd") %>%
        max()
    current_modified_file <-
        dir() %>%
        file.info %>%
        tibble::rownames_to_column() %>%
        dplyr::filter(rowname %>% str_detect("\\.Rmd$")) %>%
        filter(
            mtime == max(mtime)
        ) %>%
        .[1,1]
    open_list <- c("NEWS.md",a_rmd,current_modified_file)
    if (length(open) > 0) {
        purrr::map(open_list,if_open)
    }
}
JiaxiangBU/add2md documentation built on Jan. 31, 2020, 7:46 p.m.