R/doc_note.R

Defines functions file_name_raw

#' @author Jiaxiang Li
#'
#' @import rstudioapi
#' @importFrom lubridate now
#' @importFrom rebus SPC UPPER
#' @import clipr
#' @importFrom glue glue
#' @importFrom xfun write_utf8
#' @importFrom stringr str_remove_all str_c

file_name_raw <- function()
    lubridate::now() %>%
    stringr::str_remove_all(
        rebus::or('-',rebus::SPC,rebus::UPPER,':')
    ) %>%
    stringr::str_c('a',.)

# file_name_raw <-
#     if (is.na(selected())) {
#         file_name_raw0
#     } else {
#         selected()
#     }

#' Build a Rmd to jot down the daily notes
doc_note0 <- function(){
    rstudioapi::documentNew('',type='rmarkdown')
    file_name <-
        file_name_raw %>%
        clipr::write_clip()
    text <-
        stringr::str_c(file_name,'.Rmd is already built.')
    cat(
        sep="\n"
        ,text
        ,tips()
    )
}

doc_note <- function(){
    input <- glue::glue("---
                author: Jiaxiang Li
                date: \"`r Sys.Date()`\"
                output: github_document
                ---")
    name <- stringr::str_c(file_name_raw(),".Rmd")
    xfun::write_utf8(input,name)
    text <-
        stringr::str_c(name,' is already built.')
    cat(
        sep="\n"
        ,text
        ,tips()
    )
    rstudioapi::navigateToFile(name)
    rstudioapi::setCursorPosition(Inf)
}
JiaxiangBU/add2md documentation built on Jan. 31, 2020, 7:46 p.m.