Skip to content

Commit c68b8eb

Browse files
committed
clean up
1 parent 91a0e38 commit c68b8eb

2 files changed

Lines changed: 59 additions & 59 deletions

File tree

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@ Keeping this comprehensive will require input from the community.
66

77
So please email sacro.contact@uwe.ac.uk, or [raise an issue on the GitHub repository](https://github.com/AI-SDC/ACRO-R/issues/new/choose) if:
88
- you have a setting that is not covered, or
9-
- the steps outlined below do not work for you,
9+
- the steps outlined below do not work for you,
1010

11-
**Please note**: most of the scenarios below assume that
11+
**Please note**: most of the scenarios below assume that
1212
- you have a working version of Python 3 (version 3.9 or higher) on your system
1313
- you are able to access a terminal or command prompt to write and execute some commands.
1414

1515
---
1616

1717
## Step 1 create a python virtual environment and install the base python package *acro*
18-
**In every case** we recommend that you create what is called a 'python virtual environment' called **r-acro**.
19-
Virtual environments (*venv's*) are recommended best practice.
20-
This is because they isolate the impact of any changes you make in one venv - such as adding or updating a package- from the rest of your system.
18+
**In every case** we recommend that you create what is called a 'python virtual environment' called **r-acro**.
19+
Virtual environments (*venv's*) are recommended best practice.
20+
This is because they isolate the impact of any changes you make in one venv - such as adding or updating a package- from the rest of your system.
2121

2222
There are many tutorials available on the web if you get stuck.
2323
We do not endorse any particular site, but here are some examples:
2424
- [an overview with examples for windows/linux/mac](https://python.land/virtual-environments/virtualenv)
2525
- [another that also contains instructions for VSCode and Pycharm](https://realpython.com/python-virtual-environments-a-primer/)
26-
27-
**For individual users** we suggest that you do this in your home directory where you should have write permission.
26+
27+
**For individual users** we suggest that you do this in your home directory where you should have write permission.
2828

2929
**To install site-wide** we assume you have access rights and know where your organisation's preferred locations are (for example, this might be ```/usr/local``` on a linux system).
3030

3131
### Make a dedicated virtual environment
3232
You can make a new virtual environment via:
3333
- the Anaconda GUI interface to the conda system
34-
- command line access - by opening a terminal or command prompt and entering the command:
34+
- command line access - by opening a terminal or command prompt and entering the command:
3535
```sh
3636
conda create --n r-acro
3737
```
38-
if you have a version of conda installed or
38+
if you have a version of conda installed or
3939
```sh
4040
python -m venv ./r-acro
4141
```
@@ -49,7 +49,7 @@ Anaconda comes with its own GUI to makes this process easy.
4949
conda activate r-acro
5050
conda install conda-forge::acro
5151

52-
#assuming this completes successfuly you can now exit
52+
#assuming this completes successfully you can now exit
5353
conda deactivate r-acro
5454
```
5555

@@ -63,7 +63,7 @@ r-acro\Scripts\Activate.ps1
6363
followed by
6464
```sh
6565
python -m pip install acro
66-
#assuming this completes successfuly you can now exit the virtual environment
66+
#assuming this completes successfully you can now exit the virtual environment
6767
deactivate
6868
```
6969

@@ -73,17 +73,17 @@ deactivate
7373
source r-acro/bin/activate
7474
#you should see the your command prompt change to show (r-acro)
7575
python -m pip install acro
76-
#assuming this completes successfuly you can now exit the virtual environment
77-
deactivate
76+
#assuming this completes successfully you can now exit the virtual environment
77+
deactivate
7878
```
7979
---
8080

8181
## Step 2 Install the R packages *reticulate* and *acro*
8282

8383
The *reticulate* package is the industry-standard method for supporting communications between R and Python.
84-
It provides the `plumbing` between the R `front-end'
84+
It provides the `plumbing` between the R `front-end'
8585

86-
These commands should work whether you are
86+
These commands should work whether you are
8787
- working on a machine outside the TRE: in which case packages should install from a mirror of the CRAN service
8888
- working on a machine inside a TRE: in which case the administrator should have set up a local mirror of approved packages from CRAN
8989

@@ -94,7 +94,7 @@ install.packages*("reticulate")
9494
install.packages("acro")
9595
```
9696

97-
**For adminstrators wishing to install for all users site-wide** the commands are the same but you will need to run them in *sudo* mode.
97+
**For administrators wishing to install for all users site-wide** the commands are the same but you will need to run them in *sudo* mode.
9898

9999
---
100100

@@ -105,7 +105,7 @@ What we need to do is to set the value of a global variable ```RETICULATE_PYTHON
105105
The [R documentation for doing this](https://rstudio.github.io/reticulate/articles/versions.html) is a little inconsistent here, but the following options all seem to work.
106106

107107
### Option 1- For individuals using RStudio
108-
If you follow the menu items from ```Tools->Project Options ->Python``` or ```Tools->Global Options->Python``` you can tell it to use the version of python from the virtual environment you create in step 1, either for a specifc R project or for all your sessions as shown below
108+
If you follow the menu items from ```Tools->Project Options ->Python``` or ```Tools->Global Options->Python``` you can tell it to use the version of python from the virtual environment you create in step 1, either for a specific R project or for all your sessions as shown below
109109

110110
![This is what it looks like: step0](./imgs-for-installation-guides/settingpython-rstudio-step0.png)
111111

@@ -128,7 +128,7 @@ If you follow the menu items from ```Tools->Project Options ->Python``` or ```To
128128
library(reticulate)
129129
library("acro)"
130130
```
131-
131+
132132
### Option 3 - Editing your personal R preferences
133133
In your home directory create (or edit) the file ```.Rprofile``` file, adding the lines
134134

@@ -139,5 +139,5 @@ Sys.setenv(RETICULATE_PYTHON_ENV=file.path(Sys.getenv("USERPROFILE"),"r-acro"))
139139

140140

141141

142-
### Option 4- Making site-wide changes
142+
### Option 4- Making site-wide changes
143143
You can also edit the [site-wide Rprofile]() file to add these global environment variables, using replacing *~/r-acro* with the path to wherever you created the dedicated virtual environment.

example-notebook.Rmd

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ acro_init()
2525
```
2626

2727
### Load the data
28-
- The dataset used in this example notebook is the nursery dataset from OpenML.
29-
- The code below reads the data from a folder called "nursery_data" which we assume is at the same level as the folder where you are working.
28+
- The dataset used in this example notebook is the nursery dataset from OpenML.
29+
- The code below reads the data from a folder called "nursery_data" which we assume is at the same level as the folder where you are working.
3030
- The path might need to be changed if the data has been downloaded and stored elsewhere.
3131
```{r}
32-
data = farff::readARFF("nursery_data/nursery.arff")
33-
data = as.data.frame(data)
32+
data <- farff::readARFF("nursery_data/nursery.arff")
33+
data <- as.data.frame(data)
3434
3535
names(data)[names(data) == "class"] <- "recommend"
3636
```
3737

3838
- Convert the children column to integers, replacing 'more' with random int from range 4-10
3939

4040
```{r}
41-
data$children <-as.numeric(as.character(data$children))
42-
data[is.na(data)] <- round(runif(sum(is.na(data)), min = 4, max = 10),0)
41+
data$children <- as.numeric(as.character(data$children))
42+
data[is.na(data)] <- round(runif(sum(is.na(data)), min = 4, max = 10), 0)
4343
unique(data$children)
4444
```
4545

@@ -48,35 +48,35 @@ unique(data$children)
4848
#### ACRO Crosstab
4949

5050
```{r}
51-
index = data[, c("recommend")]
52-
columns = data[, c("parents")]
53-
values = data[, c("children")]
51+
index <- data[, c("recommend")]
52+
columns <- data[, c("parents")]
53+
values <- data[, c("children")]
5454
5555
# convert the values to an array
56-
values = matrix(values, ncol=1)
56+
values <- matrix(values, ncol = 1)
5757
58-
table = acro_crosstab(index = index, columns= columns, values = values, aggfunc = "sum")
58+
table <- acro_crosstab(index = index, columns = columns, values = values, aggfunc = "sum")
5959
table
6060
```
6161

6262
#### ACRO table
6363

6464
```{r}
65-
index = data[, c("parents")]
66-
columns = data[, c("social")]
65+
index <- data[, c("parents")]
66+
columns <- data[, c("social")]
6767
68-
table = acro_table(index=index, columns=columns, deparse.level=1)
68+
table <- acro_table(index = index, columns = columns, deparse.level = 1)
6969
table
7070
```
7171

7272
#### ACRO pivot table
7373

7474
```{r}
75-
index = "parents"
76-
values = "children"
77-
aggfunc = list("mean", "std")
75+
index <- "parents"
76+
values <- "children"
77+
aggfunc <- list("mean", "std")
7878
79-
table = acro_pivot_table(data, values=values, index=index, aggfunc=aggfunc)
79+
table <- acro_pivot_table(data, values = values, index = index, aggfunc = aggfunc)
8080
table
8181
```
8282
#### ACRO histogram
@@ -91,9 +91,9 @@ In this example a different data set will be used. The lung dataset from the sur
9191
```{r}
9292
# Load the lung dataset
9393
data(lung)
94-
#head(lung)
94+
# head(lung)
9595
96-
acro_surv_func(time=lung$time, status=lung$status, output ="plot")
96+
acro_surv_func(time = lung$time, status = lung$status, output = "plot")
9797
```
9898

9999
### Examples of producing regression outputs using acro
@@ -104,27 +104,27 @@ acro_surv_func(time=lung$time, status=lung$status, output ="plot")
104104

105105
```{r}
106106
data$recommend <- as.character(data$recommend)
107-
data$recommend[which(data$recommend=="not_recom")] <- "0"
108-
data$recommend[which(data$recommend=="recommend")] <- "1"
109-
data$recommend[which(data$recommend=="very_recom")] <- "2"
110-
data$recommend[which(data$recommend=="priority")] <- "3"
111-
data$recommend[which(data$recommend=="spec_prior")] <- "4"
107+
data$recommend[which(data$recommend == "not_recom")] <- "0"
108+
data$recommend[which(data$recommend == "recommend")] <- "1"
109+
data$recommend[which(data$recommend == "very_recom")] <- "2"
110+
data$recommend[which(data$recommend == "priority")] <- "3"
111+
data$recommend[which(data$recommend == "spec_prior")] <- "4"
112112
data$recommend <- as.numeric(data$recommend)
113113
```
114114

115115
```{r}
116116
# extract relevant columns
117-
df = data[, c("recommend", "children")]
117+
df <- data[, c("recommend", "children")]
118118
# drop rows with missing values
119-
df = df[complete.cases(df), ]
119+
df <- df[complete.cases(df), ]
120120
# formula to fit
121-
formula = "recommend ~ children"
121+
formula <- "recommend ~ children"
122122
```
123123

124124
#### ACRO Linear Model
125125

126126
```{r}
127-
acro_lm(formula=formula, data=df)
127+
acro_lm(formula = formula, data = df)
128128
```
129129

130130
#### ACRO Logit Model
@@ -133,25 +133,25 @@ We use a different combination of variables from the original dataset.
133133

134134
```{r}
135135
# extract relevant columns
136-
df = data[, c("finance", "children")]
136+
df <- data[, c("finance", "children")]
137137
# drop rows with missing values
138-
df = df[complete.cases(df), ]
138+
df <- df[complete.cases(df), ]
139139
# convert finance to numeric
140-
df = transform(df, finance = as.numeric(finance))
140+
df <- transform(df, finance = as.numeric(finance))
141141
# subtract 1 to make 1s and 2S into 0a and 1s
142-
df$finance <- df$finance -1
142+
df$finance <- df$finance - 1
143143
# formula to fit
144-
formula = "finance ~ children"
144+
formula <- "finance ~ children"
145145
```
146146

147147
```{r}
148-
acro_glm(formula=formula, data=df, family="logit")
148+
acro_glm(formula = formula, data = df, family = "logit")
149149
```
150150

151151
#### ACRO Probit Model
152152

153153
```{r}
154-
acro_glm(formula=formula, data=df, family="probit")
154+
acro_glm(formula = formula, data = df, family = "probit")
155155
```
156156

157157
### Examples of functionality to let users manage their output
@@ -185,12 +185,12 @@ acro_add_comments("output_1", "This is a crosstab on the nursery dataset.")
185185
```
186186

187187
#### Finalise
188-
- The users must call finalise() at the end of each session.
189-
- Each output is saved to a CSV file.
190-
- The SDC analysis for each output is saved to a json file or Excel file
188+
- The users must call finalise() at the end of each session.
189+
- Each output is saved to a CSV file.
190+
- The SDC analysis for each output is saved to a json file or Excel file
191191
(depending on the extension of the name of the file provided as an input to the function)
192192

193193
```{r}
194-
#acro_finalise("RTEST", "xlsx")
194+
# acro_finalise("RTEST", "xlsx")
195195
acro_finalise("RTEST", "json")
196196
```

0 commit comments

Comments
 (0)