mm: All-in-one wrapper for the conversion between (R) Markdown,...

Description Usage Arguments Details Value Examples

View source: R/wrapper.R

Description

All-in-one wrapper for the conversion between (R) Markdown, FreeMind mind map, R code, directory structure, and HTML widget.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
mm(
  from = NA,
  input_type = c("auto", "markdown", "mindmap", "R", "dir"),
  output_type = c("widget", "mindmap", "markdown", "R", "dir"),
  root = NA,
  md_list = FALSE,
  md_eq = FALSE,
  md_braces = FALSE,
  md_bookdown = FALSE,
  md_maxlevel = "",
  r_seclabel = " --------",
  r_chunkheading = FALSE,
  dir_files = TRUE,
  dir_all = TRUE,
  dir_excluded = NA,
  dir_to = NA,
  dir_quiet = FALSE,
  widget_name = NA,
  widget_width = NULL,
  widget_height = NULL,
  widget_elementId = NULL,
  widget_options = markmapOption(preset = "colorful")
)

Arguments

from

Character. The source text of the (R) Markdown syntax text, the R code, the FreeMind mind map code, or the path to the directory.

input_type

Character. The type of the input text. It can be 'auto', 'markdown', 'mindmap', 'R', 'dir'. The default value is 'auto', which means the type will be automatically assgined according to the features of the input text.

output_type

Character. The type of the output. It can be 'widget', 'mindmap', 'markdown', 'R', 'dir'. The default value is 'widget'.

root

Character. The string displayed as the root (center) of the mind map.

md_list

Logical. whether to process lists like headings in the Markdown input.

md_eq

Logical. Whether to include LaTeX equations in the Markdown input when converted to other formats.

md_braces

Logical. Whether to remove #ID in the headings of the markdown file (usually in a bookdown> project.

md_bookdown

Logical. Whether the R Markdown syntax text is in bookdown style, i.e. # (PART), # (APPENDIX), and # References as an upper level of the Level 1 heading.

md_maxlevel

Integer or ”. The maximum level of the markdown headings that are displayed in the mind map.

r_seclabel

Character. The ending characters indicating sections in R Markdown.

r_chunkheading

Logical. Whether process the chunk label as headings.

dir_files

Logical. Whether to include files. If FALSE, only folders are included. If TRUE, folders and files are included.

dir_all

Logical. Whether to include all files in a directory. If FALSE, only the names of visible files are included (following Unix-style visibility, that is files whose name does not start with a dot). If TRUE, all file names will be included.

dir_excluded

Character. The directories which are not included in the output.

dir_to

Character. The path of the output directory.

dir_quiet

Logical. Whether to display the results of generated directories.

widget_name

Character. The name of the html widget.

widget_width

Numeric. The width of the widget.

widget_height

Numeric. The height of the widget.

widget_elementId

Character. The ID of teh Widget.

widget_options

List. Options for the markmap widget. It should be a list passed from the markmapOption() function.

Details

mm() converts between (R) Markdown syntax text, R code, FreeMind mind map code, and directory, and display them in a HTML widget. It is a wrapper for other conversion functions in this package.

Value

Desired output.

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
################################################ Example 1: From Markdown to
################################################ other outputs ####

## Source document ####
input <- system.file("examples/mindr-md.Rmd", package = "mindr")

## file.show(input) # Open the input file with the default program, if any
input_txt <- readLines(input, encoding = "UTF-8")

## Convert to mind map text, markdown outline, R script, and HTML widget ####
mm_output <- mm(input_txt, output_type = c("mindmap", "markdown", "R", "widget"))
mm_output

## Save the output texts as files ####

### mind map ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".mm")
writeLines(mm_output$mindmap, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### markdown outline ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".md")
writeLines(mm_output$markdown, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### R script ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".R")
writeLines(mm_output$r, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### Widget #### output <- tempfile(pattern = 'file', tmpdir = tempdir(),
### fileext = '.html') htmlwidgets::saveWidget(mm_output$widget, file =
### output) file.show(output) # Open the output file with the default program,
### if any message('Input: ', input, '\nOutput: ', output) file.remove(output)
### # remove the output file

## Generate directory according to the source document ####
temp_dir <- file.path(tempdir(), "mindr")
mm_output <- mm(input_txt, output_type = "dir", root = "mindr", md_list = TRUE,
    md_braces = TRUE, md_bookdown = TRUE, dir_to = temp_dir)
# system2('open', temp_dir) # Open the generated directory unlink(temp_dir,
# recursive = TRUE) # remove the generated directory

## More arguments ####
mm_output <- mm(input_txt, output_type = c("mindmap", "markdown", "R", "widget"),
    root = "mindr", md_list = TRUE, md_braces = TRUE, md_bookdown = TRUE)
mm_output

################################################ Example 2: From mind map to
################################################ other outputs ####

## Source document ####
input <- system.file("examples/mindr-mm.mm", package = "mindr")

## file.show(input) # Open the input file with the default program, if any
input_txt <- readLines(input, encoding = "UTF-8")

## Convert markdown outline, R script, and HTML widget ####
mm_output <- mm(input_txt, output_type = c("markdown", "R", "widget"))
mm_output

## Save the output texts as files ####

### markdown outline ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".md")
writeLines(mm_output$markdown, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### R script ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".R")
writeLines(mm_output$r, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### Widget #### output <- tempfile(pattern = 'file', tmpdir = tempdir(),
### fileext = '.html') htmlwidgets::saveWidget(mm_output$widget, file =
### output) file.show(output) # Open the output file with the default program,
### if any message('Input: ', input, '\nOutput: ', output) file.remove(output)
### # remove the output file

## Generate directory according to the source document ####
temp_dir <- file.path(tempdir(), "mindr")
mm_output <- mm(input_txt, output_type = "dir", root = "mindr", dir_to = temp_dir)
# system2('open', temp_dir) # Open the generatecd directory unlink(temp_dir,
# recursive = TRUE) # remove the generated directory

################################################ Example 3: From R script to
################################################ other outputs ####

## Source document ####
input <- system.file("examples/mindr-r.R", package = "mindr")

## file.show(input) # Open the input file with the default program, if any
input_txt <- readLines(input, encoding = "UTF-8")

## Convert to mind map text, markdown text, and HTML widget ####
mm_output <- mm(input_txt, output_type = c("mindmap", "markdown", "widget"))
mm_output

## Save the output texts as files ####

### mind map ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".mm")
writeLines(mm_output$mindmap, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### R markdown ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".Rmd")
writeLines(mm_output$markdown, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### Widget #### output <- tempfile(pattern = 'file', tmpdir = tempdir(),
### fileext = '.html') htmlwidgets::saveWidget(mm_output$widget, file =
### output) file.show(output) # Open the output file with the default program,
### if any message('Input: ', input, '\nOutput: ', output) file.remove(output)
### # remove the output file

## Generate directory according to the source document ####
temp_dir <- file.path(tempdir(), "mindr")
mm_output <- mm(input_txt, output_type = "dir", root = "mindr", dir_to = temp_dir)
# system2('open', temp_dir) # Open the generated directory unlink(temp_dir,
# recursive = TRUE) # remove the generated directory

################################################# Example 4: From directory to
################################################# other outputs ####

## Source directory ####
input <- system.file(package = "mindr")

## Convert to mind map text, markdown outline, R script, and HTML widget ####
mm_output <- mm(input, output_type = c("mindmap", "markdown", "R", "widget"))
mm_output

## Save the output texts as files ####

### mind map ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".mm")
writeLines(mm_output$mindmap, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### markdown outline ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".md")
writeLines(mm_output$markdown, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### R script ####
output <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".R")
writeLines(mm_output$r, output, useBytes = TRUE)
# file.show(output) # Open the output file with the default program, if any
message("Input:  ", input, "\nOutput: ", output)
# file.remove(output) # remove the output file

### Widget #### output <- tempfile(pattern = 'file', tmpdir = tempdir(),
### fileext = '.html') htmlwidgets::saveWidget(mm_output$widget, file =
### output) file.show(output) # Open the output file with the default program,
### if any message('Input: ', input, '\nOutput: ', output) file.remove(output)
### # remove the output file

## Clone the source directory ####
temp_dir <- file.path(tempdir(), "mindr")
mm_output <- mm(input, output_type = "dir", dir_to = temp_dir)
# system2('open', temp_dir) # Open the generated directory unlink(temp_dir,
# recursive = TRUE) # remove the generated directory

################################################ Example 5: From any format to
################################################ mind map ####

# With the help of pandoc, you can display the outline of any documents that
# pandoc can convert to Markdown.

# # HTML: here we use the R-FQA webpage myurl <-
# 'https://cran.r-project.org/doc/FAQ/R-FAQ.html' input <- tempfile(pattern =
# 'file', tmpdir = tempdir()) markdown_temp <- tempfile(pattern = 'file',
# tmpdir = tempdir(), fileext = '.md') download.file(myurl, destfile = input,
# method = 'curl') rmarkdown::pandoc_convert(input, to = 'markdown', output =
# markdown_temp) input_txt <- readLines(markdown_temp, encoding = 'UTF-8')
# mindr::mm(input_txt)

# # MS Word: here we use a .docx document shipped by the 'officer' package
# input <- system.file('doc_examples/example.docx', package = 'officer')
# markdown_temp <- tempfile(pattern = 'file', tmpdir = tempdir(), fileext =
# '.md') rmarkdown::pandoc_convert(input, to = 'markdown', output =
# markdown_temp) input_txt <- readLines(markdown_temp, encoding = 'UTF-8')
# mindr::mm(input_txt, md_list = TRUE)

mindr documentation built on Nov. 22, 2021, 9:07 a.m.

Related to mm in mindr...