This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
README.rmd
180 lines (123 loc) · 5.1 KB
/
README.rmd
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
original_files <- dir()
```
<!-- # ijtiff <img src="man/figures/logo.png" height="140" align="right"> -->
<!-- Code status -->
[![Build Status](https://travis-ci.org/ROpenSci/Rclean.svg?branch=master)](https://travis-ci.org/ROpenSci/Rclean)
[![Coverage status](https://codecov.io/gh/ROpenSci/Rclean/branch/master/graph/badge.svg)](https://codecov.io/github/ROpenSci/Rclean?branch=master)
<!-- R status -->
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/Rclean)](https://cran.r-project.org/package=Rclean)
![RStudio CRAN downloads](http://cranlogs.r-pkg.org/badges/grand-total/Rclean)
![RStudio CRAN monthly downloads](http://cranlogs.r-pkg.org/badges/Rclean)
[![Rdocumentation](http://www.rdocumentation.org/badges/version/Rclean)](http://www.rdocumentation.org/packages/Rclean)
<!-- Dev status -->
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing)
<!-- Package Review -->
[![](https://badges.ropensci.org/327_status.svg)](https://github.com/ropensci/software-review/issues/327)
[![status](http://joss.theoj.org/papers/334d80d5508056dc6e7e17c6fd3ed5a6/status.svg)](http://joss.theoj.org/papers/334d80d5508056dc6e7e17c6fd3ed5a6)
<!-- Archiving -->
[![DOI](https://zenodo.org/badge/102645585.svg)](https://zenodo.org/badge/latestdoi/102645585)
Quick Start Guide
=================
- [Rclean](https://github.com/MKLau/Rclean) was created to help
scientists more *easily* write “cleaner” code.
- Written with research scientists that are results oriented in mind,
the package’s primary function provides a simple way to isolate
the minimal code you need to produce a specific result, such as a
statistical table or a figure. By focusing on specific results
(aka. variables), large and/or complicated analytical scripts can
be paired down to the essentials and easily re-factored to be more
robust and easily shared.
- Below, you'll find a brief introduction to get you started using the
package. For more details, see `vignette("Rclean")`.
Install
=======
You can install the most up to date version easily with
[devtools](https://github.com/hadley/devtools):
```{r eval = FALSE}
install.packages("devtools")
devtools::install_github("MKLau/Rclean")
```
You will also likely need to install the
[RGraphViz](bioconductor.org/packages/release/bioc/html/Rgraphviz.html):
```{R install_rgraphviz, eval = FALSE}
install.packages("BiocManager")
BiocManager::install("Rgraphviz")
```
Once installed, per usual R practice just load the *Rclean* package
with:
```{r eval = TRUE}
library(Rclean)
```
Usage
=====
```{r eval = TRUE, echo = FALSE, results = "hide"}
library(CodeDepends)
script <- system.file(
"example",
"simple_script.R",
package = "Rclean")
```
*Rclean* usage is simple. Have a script with code you want to clean
saved to disk. Then, just run the `clean` function with the path to
the script as the input. Here, we can use an example script that is
included with the package:
```{r eval = FALSE}
script <- system.file("example", "simple_script.R", package = "Rclean")
```
Here's a quick look at the code:
```{r eval = TRUE}
readLines(script)
```
You can get a list of the variables found in an object with
`get_vars`.
```{r eval = TRUE}
get_vars(script)
```
Sometimes for more complicated scripts, it can be helpful to see a
network graph showing the interdependencies of
variables. `code_graph` will produce a network diagram showing which
lines of code produce or use which variables:
```{r eval = TRUE, out.width = "75%", dpi = 300}
code_graph(script)
```
Now, we can pick the result we want to focus on for cleaning:
```{r eval = TRUE}
clean(script, "tab.15")
```
We can also select several variables at the same time:
```{r eval = TRUE}
my.vars <- c("tab.12", "tab.15")
clean(script, my.vars)
```
While just taking a look at the simplified code can be very helpful,
you can also save the code for later use or sharing (e.g. creating a
reproducible example for getting help) with `keep`:
```{r eval = FALSE}
my.code <- clean(script, my.vars)
keep(my.code, file = "results_tables.R")
```
If you would like to copy your code to your clipboard, you can do that
by not specifying a file path. You can now paste the simplified as needed.
```{r eval = FALSE}
keep(my.code)
```
Contributing
============
This is an open-source project. If you would like to contribute to the
project, please check out [CONTRIBUTING.md](CONTRIBUTING.md).
Please note that the 'Rclean' project is released with a
[Contributor Code of Conduct](CODE_OF_CONDUCT.md).
By contributing to this project, you agree to abide by its terms.
![ropensci_footer](https://ropensci.org/public_images/ropensci_footer.png)