[education/rkward/snippets] rkward: fixes on R snippets, addtion of data.frame[] and c()

Stefan Rödiger null at kde.org
Sun Jun 19 12:34:49 BST 2022


Git commit 958d9a9b9c6b8c0f605023aefe3732ab3b5e5ea2 by Stefan Rödiger.
Committed on 19/06/2022 at 07:41.
Pushed by srodiger into branch 'snippets'.

fixes on R snippets, addtion of data.frame[] and c()

M  +49   -42   rkward/RKWardR.xml
M  +98   -34   rkward/RKWardRMd.xml

https://invent.kde.org/education/rkward/commit/958d9a9b9c6b8c0f605023aefe3732ab3b5e5ea2

diff --git a/rkward/RKWardR.xml b/rkward/RKWardR.xml
index 54f23733..56b9c11b 100644
--- a/rkward/RKWardR.xml
+++ b/rkward/RKWardR.xml
@@ -1,5 +1,5 @@
-<snippets name="LaTeX (RKWard)" filetypes="tex" authors="RKWard Team" namespace="SnippetsLaTeX" license="BSD">
- <script>require("range.js")
+<snippets name="R (RKWard)" filetypes="R" authors="RKWard Team" namespace="SnippetsR" license="BSD">
+  <script>require("range.js")
 require("cursor.js")
 require("document.js")
 require("view.js")
@@ -29,59 +29,66 @@ function rangeCommand(command, def) {
 }
 </script>
  <item>
-  <match>Newline</match>
-  <fillin>\newline</fillin>
+  <match>Figure as PDF</match>
+  <fillin>
+pdf(fi­len­ame­="my­plo­t.p­df", width=5, height=5)
+plot(rnorm(100))
+dev.off()
+  </fillin>
  </item>
  <item>
-  <match>x=y</match>
-  <fillin>$x = y$</fillin>
+  <match>Plotting area (3x3 array)</match>
+  <fillin>
+# Plotting area (3x3 array) with 3 rows and 3 columns
+par(mf­row­=c(­3,3))
+  </fillin>
  </item>
  <item>
-  <match>α Α</match>
-  <fillin>$\alpha A$</fillin>
+  <match>Matrix multip­lic­ation</match>
+  <fillin>
+%*%
+  </fillin>
  </item>
  <item>
-  <match>|A|</match>
-  <fillin>$|A|$</fillin>
+  <match>Concat­enate vectors after converting to character</match>
+  <fillin>
+paste(…, sep = " ", collapse = NULL)
+  </fillin>
  </item>
  <item>
-  <match>x∈A</match>
-  <fillin>$x \in A$</fillin>
- </item>
- <item>
-  <match>P(A∣B)</match>
-  <fillin>$P(A \mid B)$</fillin>
- </item>
- <item>
-  <match>Overlined</match>
-  <fillin>$\overline{x}$</fillin>
- </item>
- <item>
-  <match>Hat</match>
-  <fillin>$\hat{x}$</fillin>
- </item>
- <item>
-  <match>Tile</match>
-  <fillin>$\tilde{x}$</fillin>
- </item>
- <item>
-  <match>Subset</match>
-  <fillin>$x \subset B$</fillin>
+  <match>for loop</match>
+  <fillin>
+# Print for 10 capital LETTERS
+for(i in 1:10){
+    print(LETTERS[i])
+}
+  </fillin>
  </item>
  <item>
-  <match>Subset equal</match>
-  <fillin>$x \subseteq B$</fillin>
+  <match>while loop</match>
+  <fillin>
+while(condi­tion){
+    Do something
+}
+  </fillin>
  </item>
  <item>
-  <match>Or</match>
-  <fillin>$A \cup B$</fillin>
+  <match>ifelse statement</match>
+  <fillin>
+if (condi­tion){
+    Do something
+    } else {
+    Do something different
+    }
+  </fillin>
  </item>
  <item>
-  <match>And</match>
-  <fillin>$A \cap B$</fillin>
+  <match>data.frame</match>
+  <fillin>${rangeCommand("data.frame(%%1, row.names = NULL, check.rows = FALSE, check.names = TRUE, fix.empty.names = TRUE, stringsAsFactors = FALSE)", "Data object")}
+  </fillin>
  </item>
- <item>
-  <match>And</match>
-  <fillin>$A \cap B$</fillin>
+  <item>
+  <match>Combine Values into a Vector or List</match>
+  <fillin>${rangeCommand("c(%%1, recursive = FALSE, use.names = TRUE)", "Objects to be concatenated")}</fillin>
  </item>
-</snippets>
+ </snippets>
diff --git a/rkward/RKWardRMd.xml b/rkward/RKWardRMd.xml
index 88fdfd5b..4e50221e 100644
--- a/rkward/RKWardRMd.xml
+++ b/rkward/RKWardRMd.xml
@@ -1,4 +1,4 @@
-<snippets name="R (RKWard)" filetypes="R" authors="RKWard Team" namespace="SnippetsR" license="BSD">
+<snippets name="R Markdown (RKWard)" filetypes="R Markdown" authors="RKWard Team" namespace="SnippetsRmd" license="BSD">
   <script>require("range.js")
 require("cursor.js")
 require("document.js")
@@ -29,57 +29,121 @@ function rangeCommand(command, def) {
 }
 </script>
  <item>
-  <match>Figure as PDF</match>
-  <fillin>
-pdf(fi­len­ame­="my­plo­t.p­df", width=5, height=5)
-plot(rnorm(100))
-dev.off()
-  </fillin>
+  <match>Heading1</match>
+  <fillin>${lineCommand("#", "^#+ ", "Heading")}</fillin>
  </item>
  <item>
-  <match>Plotting area (3x3 array)</match>
-  <fillin>
-# Plotting area (3x3 array) with 3 rows and 3 columns
-par(mf­row­=c(­3,3))
-  </fillin>
+  <match>Heading2</match>
+  <fillin>${lineCommand("##", "^#+ ", "Heading")}</fillin>
+ </item>
+ <item>
+  <match>Heading3</match>
+  <fillin>${lineCommand("###", "^#+ ", "Heading")}</fillin>
+ </item>
+ <item>
+  <match>List (Unordered)</match>
+  <fillin>${rangeCommand("\n- A\n- B\n- C\n\n")}</fillin>
+ </item>
+ <item>
+  <match>List (Ordered)</match>
+  <fillin>${rangeCommand("\n1. A\n2. B\n3. C\n\n")}</fillin>
+ </item>
+ <item>
+  <match>List (Unordered & Nested)</match>
+  <fillin>${rangeCommand("\n- A\n  - a\n- B\n  - b\n- C\n  - c\n\n")}</fillin>
+ </item>
+ <item>
+  <match>Bold</match>
+  <fillin>${rangeCommand("**%%1**", "Bold")}</fillin>
+ </item>
+ <item>
+  <match>Italics</match>
+  <fillin>${rangeCommand("*%%1*", "Italics")}</fillin>
+ </item>
+ <item>
+  <match>Superscript</match>
+  <fillin>${rangeCommand("\n$A^2^$\n")}</fillin>
+ </item>
+ <item>
+  <match>Subscript</match>
+  <fillin>${rangeCommand("\n$H~2~O$\n")}</fillin>
+ </item>
+ <item>
+  <match>En dash</match>
+  <fillin>--</fillin>
  </item>
  <item>
-  <match>Matrix multip­lic­ation</match>
+  <match>Em dash</match>
+  <fillin>---</fillin>
+ </item>
+ <item>
+  <match>Equation (inline)</match>
   <fillin>
-%*%
-  </fillin>
+$e^${braces("i\\pi")} + 1$
+</fillin>
  </item>
  <item>
-  <match>Concat­enate vectors after converting to character</match>
+  <match>Equation (block)</match>
   <fillin>
-paste(…, sep = " ", collapse = NULL)
-  </fillin>
+$$e^${braces("i\\pi")} + 1$$
+</fillin>
+ </item>
+ <item>
+  <match>Strikethrough</match>
+  <fillin>${rangeCommand("~~%%1~~", "Strikethrough")}</fillin>
  </item>
  <item>
-  <match>for loop</match>
+  <match>Link</match>
+  <fillin>${rangeCommand("(title)[%%1]", "URL")}</fillin>
+ </item>
+ <item>
+  <match>rmarkdown::render()</match>
+  <fillin>rmarkdown::render()</fillin>
+ </item>
+ <item>
+  <match>Code (inline)</match>
+  <fillin>${rangeCommand("`r %%1`", "paste(\"The sum of 1 to 1000 is\", sum(1L:1000))")}</fillin>
+ </item>
+  <item>
+  <match>Code (simple chunk)</match>
+  <fillin>${rangeCommand("\n```"+ braces("r") +" %%1```\n", "\nx <- 1\n\n")}</fillin>
+ </item>
+ <item>
+  <match>Quote</match>
+  <fillin>${rangeCommand("> %%1", "Text")}</fillin>
+ </item>
+ <item>
+  <match>Code (chunk with defaults)</match>
+  <fillin>${rangeCommand("\n```"+ braces("r, echo = FALSE, eval = FALSE, fig.show = \"hide\", include = FALSE, message = FALSE, results = \"hide\", warning = FALSE") +" %%1```\n", "\nx <- 1\n\n")}</fillin>
+ </item>
+ <item>
+  <match>Table</match>
   <fillin>
-# Print for 10 capital LETTERS
-for(i in 1:10){
-    print(LETTERS[i])
-}
+| Right  | Left  | Default   | Center    |
+|-------:|:------|-----------|:---------:|
+| 12     | 12    | 12        | 12        |
+| 123    | 123   | 123       | 123       |
+| 1      | 1     | 1         | 1         |
   </fillin>
  </item>
  <item>
-  <match>while loop</match>
+  <match>Table with caption</match>
   <fillin>
-while(condi­tion){
-    Do something
-}
+| Right  | Left  | Default   | Center    |
+|-------:|:------|-----------|:---------:|
+| 12     | 12    | 12        | 12        |
+| 123    | 123   | 123       | 123       |
+| 1      | 1     | 1         | 1         |
+:Caption text
   </fillin>
  </item>
  <item>
-  <match>ifelse statement</match>
+  <match>Table (kable)</match>
   <fillin>
-if (condi­tion){
-    Do something
-    } else {
-    Do something different
-    }
+```{r}
+data <- iris[1:4, ]
+knitr::kable(data, caption = "Table caption text.")
+```
   </fillin>
  </item>
- </snippets>
+</snippets>



More information about the rkward-tracker mailing list