--- title: "Draw a tree of your package files and functions" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Draw a tree of your package files and functions} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ``` ```{r} library(fusen) ``` # Get a tree of the package structure to help developers `get_package_structure()` is a function that helps developers understand the package structure. It reads the `dev/config_fusen.yaml` file, adds the list of resulting functions and extra description of files. You can know: - The description of the flat file as issued from its Title when exists - If the flat file is still active - The list of R files issued from the flat file - The list of functions inside these R files - The list of files of tests issued from the flat file - There is a possibility to list all functions that are called in the test files - The vignette issued from the flat file With `draw_package_structure()`, you can draw a tree of the package structure in the console. This also works for any R package, not only for `fusen` built packages. ```{r examples-get_package_structure} #| eval: yes #' \dontrun{ #' # This only works inside a 'fusen' built package #' pkg_structure <- get_package_structure() #' draw_package_structure(pkg_structure) #' } #' #' # Example with a dummy package dummypackage <- tempfile("drawpkg.structure") dir.create(dummypackage) # {fusen} steps fill_description(pkg = dummypackage, fields = list(Title = "Dummy Package")) dev_file <- suppressMessages( add_flat_template(pkg = dummypackage, overwrite = TRUE, open = FALSE) ) flat_file <- dev_file[grepl("flat_", dev_file)] usethis::with_project(dummypackage, { # Add an extra R file with internal function # to list in "keep" dir.create("R") cat("extra_fun <- function() {1}\n", file = "R/my_extra_fun.R") # Works with classical package pkg_structure <- get_package_structure() draw_package_structure(pkg_structure) }) usethis::with_project(dummypackage, { # Works with 'fusen' package suppressMessages( inflate( pkg = dummypackage, flat_file = flat_file, vignette_name = "Get started", check = FALSE, open_vignette = FALSE ) ) pkg_structure <- get_package_structure() draw_package_structure(pkg_structure) }) ``` # Get the list of functions from a R file ```{r example-get_all_created_funs} file_path <- tempfile(fileext = ".R") cat( "my_fun <- function() {1}", "my_fun2 <- function() {2}", sep = "\n", file = file_path ) get_all_created_funs(file_path) ```