scriptResume
created: 2023-05-16, updated: 2025-05-01, version 0.1.6
scriptResume.Rmd
scriptResume
is a R addin package that aims to
facilitate the coding process. It comes especially handy after combined
with keyboard short cuts. Currently, there are two section of functions
implemented - editing functions and script reading functions.
Editing functions
These addin functions help to facilitate coding process.
- Objects to quoted text
- Remove row ID
- Upper case
- Lower case
- Remove quotes
- Roxygen comment
- Roxygen uncomment
- Roxygen quote
- to bullet point
- to table
Copy & paste related features
Object to quoted text
transforms a chunk of selected
text with comma separator into a string vector. For example, from
a, b, c, d
to
c("a", "b", "c", "d")
Remove row ID
remove the row IDs from the text copied
from the console.
[1] "1 m = 722" "10 m = 584" "11 m = 427" "12 m = 380"
[5] "13 m = 243" "14 m = 211" "15 m = 321" "16 m = 316"
[9] "17 m = 220" "18 m = 152" "19 m = 1906" "2 m = 737"
[13] "20 m = 164" "21 m = 108" "22 m = 269" "3 m = 507"
[17] "4 m = 498" "5 m = 412" "6 m = 7836" "7 m = 569"
[21] "8 m = 379" "9 m = 297"
to
"1 m = 722" "10 m = 584" "11 m = 427" "12 m = 380"
"13 m = 243" "14 m = 211" "15 m = 321" "16 m = 316"
"17 m = 220" "18 m = 152" "19 m = 1906" "2 m = 737"
"20 m = 164" "21 m = 108" "22 m = 269" "3 m = 507"
"4 m = 498" "5 m = 412" "6 m = 7836" "7 m = 569"
"8 m = 379" "9 m = 297"
remove quotes
function will remove any quotation marks
in the selected text, e.g. it will change "A",'B'
to
A, B
.
Upper case
and Lower case
transform the
selected text into upper or lower cased format.
Roxygen formatting features
These features are used in the R script instead of R Markdown files. They will transform the selected text into Roxygen format comment or quoted text in Roxygen format. Alternatively it can back-tranform a chunk of Roxygen comment format text back to text in R script.
Roxygen comment
: e.g. from
This is my comment.
to
#' This is my comment.
Roxygen uncomment
: e.g. from
#' Recommenting
to Recommenting
Roxygen quote
: e.g. from Some quotes
to
#' > Some quotes
Markdown related features
to bullet point
transforms selected text into bullet
points. The selected text has to be separated by \n
.
point 1
point 2
point 3
to
- point 1
- point 2
- point 3
to table
transforms selected text, which is colon
separated entry into md
table format. For example,
a:b:c
1:2:3
4:5:6
to
a | b | c |
---|---|---|
1 | 2 | 3 |
4 | 5 | 6 |
Script reading functions
These addin functions read through the currently active script and summarize the script. The functions include:
- Insert unique libraries
- Insert header
Unique libraries
This function reads through the script and collects the libraries
used throughout the script. The function will collect libraries called
by library()
, require()
, lib::
and insert these libraries at current cursor position. It will
automatically remove duplicated usage of the same library. For
example,
require(abc)
libraries(abc)
xyz::xyz()
to
library(abc)
library(knitr)
library(lib)
library(rmarkdown)
library(xyz)
The other libraries are used in this Rmd file but not shown in this example. You will find this function handy when reading a messy script that the libraries are imported from every possible random place.
A header summary of a script
This function read through the currently active R script and
summarize the script with following information of the current computing
enviroment, hence the name of the package scriptResume
.
# ******************************************************************************
# Property of company
# Program name : scriptResume.R
# Description :
# Author : author
# Compound number : SAR
# Study code :
# Analysis code : BMK-
# Date created : 2023-05-16
# Input files : data/file1.csv,
# data/file2.Rds,
# data/file3.Rda
# Input programs : src/preprocess.R
# Packages needed : abc,
# knitr,
# lib,
# rmarkdown,
# xyz
# Outputs created : data/file2.csv,
# data/file3.Rds
# R version : R version 4.1.0 (2021-05-18)
# Platform : Linux-4.4.0-19041-Microsoft
# ******************************************************************************
# Modification status :
# In progress | 2023-05-16 | author
# Description:
# ******************************************************************************
Files imported with funcitons read*()
,
load()
, source()
will be collected
data1 <- read.csv("data/file1.csv")
data2 <- readRDS("data/file2.Rds")
load("data/file3.Rda")
source("src/preprocess.R")
Files exported with functions write*()
,
save*()
will be collected.
write.csv(data2, "data/file2.csv")
saveRDS(file3, "data/file3.Rds")
Since this function is targeted at pharma industry, it will automatically read the current working directory and output the triplet information. This illustration is tested in local so this function is not shown in the output above.
Below is an example for a dummy directory. Since I’m always working on biomarker analysis, the analysis code always starts with BMK.
# Author : e123456
# Compound number : SAR123
# Study code : LPS123
# Analysis code : BMK-CSR
R markdown theme
Starting from version 0.1.5, An Addin function, make css
will be available for generating a predefined-themed css
file. To use this function, put the cursor in the any open R script or
any type of file, which defines currently active document, then click on
the make css
button. A css file named
theme.css
will be generated in the directory of the current
active document.
Project environment
Sourcing triplet environment
Starting from version 0.1.6, this addin has a new feature for
sourcing the triplet environment. Placing the cursor in the file that is
located in a triplet environment then click on the button of
source triplet
in the addin. The current working
environment will be changed to the triplet environment the active file
is located.