knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(lazytype)
The R package lazytype provides addins for inserting code and running code in a different manner, and functions to allow interaction between scripts and between script and rmarkdown file.
The stable version on R CRAN is coming soon.
You can install the development version from Github with:
# install.packages("devtools") devtools::install_github("FinYang/lazytype")
dont_sign_me_out(hours = 3.5)
moves mouse every 5 minutes for a certain time (default 3.5 hours) and print the time elapsed in the console. It is mainly used on public PC where it signs you out for a certain period of inactivity.
LazyScript
operations helps with interacting with scripts and rmarkdown files, saves time to copy and paste and provides means to arrange code in a different way.
Assume in the current working directory there is a script file named test.R
with the following contents.
## ---- library ---- library(tidyverse) ## ---- hello ---- print("Hello World")
read_script("test.R", library = TRUE)
reads in the code in the test.R
file and executes the chunk labelled library if argument has been set to library = TRUE
.
library(lazytype) script_test <- read_script("test.R", library = TRUE)
%run%
can be used to run a chunk from test.R
file with a specified label.
script_test %run% "hello"
print("Hello World")
In other words, read_script
provides a knitr::read_chunk
equivalent in script files.
copy_script_to_rmd
copies code in the script to the rmd file in the form of chunks based on the section header.
copy_script_to_rmd("test.R", "test.Rmd", match_chunk = FALSE)
In the test.Rmd
file, after the existing text, the code in test.R
will be appended to the end in the following form.
knitr::include_graphics("test.png")
The package provides various addins, aiming to decrease keystrokes and clicks.
run_all_to_cursor
by its name, run the code in the current script above the cursor. I suggest binding this addin with shortcut Ctrl
+Alt
+R
.
run_selected_arguments
runs selected code, ignoring the comma. It normally is used to set the default arguments of a function where the arguments are separated by comma. Useful for testing function with different arguments. I suggest binding this addin with shortcut Alt
+R
.
insert_purl_section
insert ## ---- ----
at an empty line in the script, or turns a non-empty line to a comment with purl section header ## ----
(or turns it back). The header is recognised by knitr::read_chunk
to read code for each chunk in the rmarkdown file from R script. See ?knitr::read_chunk
for more details. I suggest binding this addin with shortcut Shift
+Ctrl
+Q
.
insert_rmarkdown_chunk_editlabel
insert Rmarkdown Chunk with cursor placed at the label. Just a shortcut to insert chunk without any code in it to use with knitr::read_chunk
. I suggest binding this addin with shortcut Ctrl
+Alt
+O
.
insert_scoping_assignment
insert <<-
at cursor. Binding to Alt
+=
is suggested.
This package is free and open source software, licensed under GPL-3.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.