You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: episodes/01-introduction.md
+51-57Lines changed: 51 additions & 57 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,90 +58,82 @@ Review [the Reproducible Research Discussion](./reproducible-research-discussion
58
58
59
59
## Practices for Building Better Research Software
60
60
61
-
The practices we will cover for building better research software fall into three areas.
61
+
The topics we will cover for building better research software fall into three areas.
62
62
63
-
### 1. Things you can do with your own computing environment to enhance the software
63
+
### 1. Improving your own computing environment
64
64
65
-
* Using virtual development environments ensures your software can be developed and run consistently across different systems, making it easier for you and others to run, reuse, and extend your code.
65
+
***Using virtual development environments** ensures your software works consistently across different systems, making it easier for you and others to run, reuse, and extend your code.
66
66
67
-
### 2. Things you can do to improve the source code of the software itself
67
+
### 2. Improving the source code
68
68
69
-
* Organising and structuring your code and project directory keeps your software clean, modular, and reusable, enhancing its readability, extensibility, and reusability.
70
-
* Following coding conventions for your programming language produces consistently formatted code that others find it easy to read, reuse or extend in their own examples and applications.
71
-
* Writing structured documentationstrings and comments within your code will make it more understandable to others who wish to use or extend it.
72
-
* Testing can save time spent on debugging and ensures that your code is correct and does what it is set out to do, giving you and others confidence in your code and the results it produces.
69
+
***Organising and structuring your code and project directory** keeps your software cleanand modular, enhancing its readability, extensibility, and reusability.
70
+
***Following coding conventions**produces consistently formatted code that others will find easy to work with.
71
+
***Writing structured documentation**, such as strings and comments, within your code will make it more understandable to others.
72
+
***Testing** reduces time spent debugging and ensures that your code does what you mean it to, increasing confidence in your results.
73
73
74
-
### 3. Things you can do to make the software easier for other people to use
74
+
### 3. Improving resources for collaboration
75
75
76
-
* Using version control and collaboration platforms like [GitHub](https://github.com), [GitLab](https://gitlab.com), and [CodeBerg](https://codeberg.org/) makes it easier to share code and work on it together.
77
-
* Fostering a community around your software and promoting collaboration helps to grow a user base for your software and contributes to its long-term sustainability.
78
-
* Providing clear and comprehensive documentation, including code comments, API specifications, setup guides, and usage instructions, ensures your software is easy to understand, use, and extend (by you and others).
79
-
*Accompanying your software with clear information about its licensing terms and how it should be cited ensures that others can reuse and adapt your code with confidence and that you receive credit when they do so.
76
+
***Using version control and collaboration platforms** like [GitHub](https://github.com), [GitLab](https://gitlab.com), and [CodeBerg](https://codeberg.org/) makes it easier to work on code together.
77
+
***Fostering a community**and promoting collaboration helps grow a user base for your software, contributing to its long-term sustainability.
78
+
***Providing clear and comprehensive documentation**, including code comments, API specifications, setup guides, and usage instructions, ensures your software is easy to understand, use, and extend.
79
+
***Clarifying licensing terms** and citation expectations ensures that others can use your code with confidence and that you receive credit when they do so.
80
80
81
81
:::::::::::::::::: challenge
82
82
83
-
### Tools and practices you use (5 min)
83
+
### Your Current Approach (5 min)
84
84
85
-
Individually,
85
+
Individually, reflect on the following, making notes in the shared collaborative document:
86
86
87
-
- reflect on what practices or tools you are already using in your software development workflow,
88
-
- list some new practices or tools that you would like to start employing or using.
89
-
90
-
Write your reflections in the shared collaborative document.
87
+
1. What practices or tools you are already using in your software development workflow?
88
+
2. List some new practices or tools you would like to start employing.
91
89
92
90
::::::::::::::::::
93
91
94
92
## Our Research Software Project
95
93
96
-
You are going to follow a fairly typical experience of a new researcher (e.g. a PhD student or a postdoc) joining a research group.
97
-
You were emailed some spacewalks data and analysis code bundled in the `spacewalks.zip` archive, written by another group
98
-
member who worked on similar things but has since left. You need to be able to install and run this code on your
99
-
machine, check you can understand it and then adapt it to your own project.
94
+
You are going to emulate a fairly typical experience for a new researcher (e.g. PhD student or postdoc) joining a research group.
95
+
Let's say you were emailed some data on astronaut spacewalks, bundled with analysis code in the `spacewalks.zip` archive. The code was written by a group
96
+
member who has since left. You need to be able to install and run this code on your
97
+
machine, check you can understand it, and then adapt it to your own project.
100
98
101
99
As part of the [setup for this course](./installation-instructions.html#spacewalks), you may have downloaded the `spacewalks.zip` archive.
102
100
If not, you can [download it](https://github.com/carpentries-incubator/better-research-software-r/raw/refs/heads/main/learners/spacewalks.zip) now.
103
-
Save the `spacewalks.zip` archive to your home directory and extract it - you should get a directory called `spacewalks`.
101
+
Save the `spacewalks.zip` archive to your home directory and extract it — you should get a directory called `spacewalks`.
104
102
105
103
The first thing you may want to do is inspect the content of the code and data you received. We will use RStudio for browsing,
106
-
inspecting, modifying files and running our code.
104
+
inspecting, and modifying files as well as running our code.
107
105
108
106
RStudio is a very handy tool for software development and is used by many researchers worldwide.
109
-
RStudio is an Integrated Development Environment (IDE).
110
-
IDEs are graphical application that provide a comprehensive workspace for writing, editing, testing, and debugging code - all in one place.
111
-
While RStudio is seemingly the most popular, current IDE for working with R, there are other IDEs you can use (VS code, Positron, etc).
112
-
To open our directory `spacewalks` in RStudio, we first want to make this an R project.
113
-
114
-
Having our software development project folder as a project in R is helpful for reproduciblity as well.
115
-
We will discover in the next episode the issues with "hard coding" specific filesystem paths into our project and how using R projects will help us to create consistent file path references within our project.
107
+
It is an Integrated Development Environment (IDE), which are graphical applications that provide a comprehensive workspace for writing, editing, testing, and debugging code - all in one place.
108
+
While RStudio is probably most popular IDE for working with R, there are others you can use (VS code, Positron, etc).
116
109
117
110
To open our directory `spacewalks` in RStudio, we first want to make this an R project.
118
-
Having our software development project folder as a project in R is helpful for reproduciblity as well.
119
-
We will discover in the next episode the issues with "hard coding" specific filesystem paths into our project and R projects will help us to create consistent file path references within our project.
111
+
In addition to keeping all our files for this project organized for ourselves, using the project feature in R improves reproducibility.
112
+
We will discover in the next episode the issues with "hard coding" specific filesystem paths, and how using R projects allows us to create consistent file path references.
120
113
121
-
To create a new project – go to **File -> New Project** this will open the new project setup wizard.
122
-
Choose **Existing Directory**, then navigate to where you extracted your spacewalks folder in your home directory using the **Browse...** button and click **Open** once you have selected the `spacewalks` folder.
114
+
To create a new project, open RStudio and go to **File -> New Project**. This will open the new project setup wizard.
115
+
Choose **Existing Directory**, then navigate to and select the `spacewalks` folder in your home directory using the **Browse...** button. Once the `spacewalks` folder is selected, click **Open**.
123
116
Then click **Create Project**.
124
-
RStudio will then reopen into your project.
125
-
Note, now it says `spacewalks` in the upper-right hand corner of RStudio since that project is open and the Files pane is showing the files from the `spacewalks` folder.
126
-
When you return to working on this project later, you can click on the `spackewalks.Rproj` file in your file explorer/finder window or you can use the Rproject menu in the upper-right hand side of RStudio to select which projct you would like to work in.
117
+
RStudio will then reopen into your project.
118
+
Note that it now says `spacewalks` in the upper-right hand corner of RStudio (because that is the open project). The files pane should show the files from inside the `spacewalks` folder.
119
+
When you return to work on this project later, you can open the `spacewalks.Rproj` file from your file manager (i.e., Windows' File Explorer or Mac's Finder), or you can open the project from within RStudio using the Rproject menu in the upper-right corner.
127
120
128
121
Reproducibility note: For reproducible workflows, it’s best to start each session with a clean environment. Best practice is to turn off workspace saving/loading (Tools → Global Options → General: uncheck “Restore .RData…” and set “Save workspace” to “Never”). If you are prompted to save your workspace when closing RStudio, click "No". This ensures your code runs from a fresh start every time and avoids hidden dependencies on objects left over from previous sessions.
129
122
130
123
::: instructor
131
124
Pause here for some discussion. Are there instances where saving your workspace might be useful? When or why?
132
125
:::
133
126
134
-
You may notice that the software project contains:
127
+
Opening the files pane in RStudio, you should see that the software project contains:
135
128
136
129
1. A JSON file called `data.json` - a snippet of which is shown below - with data on extra-vehicular activities
137
-
(EVAs, i.e. spacewalks) undertaken by astronauts and cosmonauts from 1965 to 2013 (data provided by NASA via its [Open Data Portal](https://data.nasa.gov/Raw-Data/Extra-vehicular-Activity-EVA-US-and-Russia/9kcy-zwvn/about_data)).
130
+
(aka EVAs or spacewalks) undertaken by astronauts and cosmonauts from 1965 to 2013 (data provided by NASA via its [Open Data Portal](https://data.nasa.gov/Raw-Data/Extra-vehicular-Activity-EVA-US-and-Russia/9kcy-zwvn/about_data)).
138
131
139
-
{alt='JSON data file snippet showing EVA/spacewalk data including EVA ID, country, crew members, vehicle type, date of the spacewalk, duration, and purpose'}
140
-
2. An R script called `my code v2.R` containing some analysis code.
132
+
{alt='JSON data file snippet showing EVA/spacewalk data including EVA ID, country, crew members, vehicle type, date of the spacewalk, duration, and purpose'}
141
133
142
-
3.`spacewalks.Rproj` the R project for this folder.
134
+
2. An R script called `my code v2.R`, containing some analysis code.
143
135
144
-
<!--- screenshot replacement needed {alt='The first few lines of a Python script used as example code for the episode'} -->
136
+
{alt='First 16 lines of the `my code v2.R` file, open in RStudio'}
145
137
146
138
The code in the R script does some common research tasks:
147
139
@@ -150,24 +142,26 @@ You may notice that the software project contains:
150
142
* Performs some calculations to generate summary statistics about the data
151
143
* Makes a plot to visualise the data
152
144
153
-
3. A folder called `astronaut-data-analysis-old` - which presumably contains previous versions of the analysis acting as some sort of a backup.
154
-
4. A hidden file `.DS_Store` - Desktop Services Store is a hidden metadata file automatically created by macOS Finder in every folder, storing user-specific view settings like icon positions, window size, and background colors, acting much like Windows' `desktop.ini`.
155
-
This makes us think that the author was using macOS operating system but this file is not part of the project itself.
145
+
3.`spacewalks.Rproj`, the R project file we just created.
146
+
147
+
4. A folder called `astronaut-data-analysis-old`, which presumably contains previous versions of the analysis, acting as a backup system.
148
+
149
+
5. A hidden file called .DS_Store. Standing for Desktop Services Store, this is a metadata file automatically created by macOS Finder, storing user-specific view settings like icon positions, window size, and background colors. The Windows equivalent is desktop.ini. This suggests that the author was using macOS operating system, but this file is not part of the project itself.
156
150
157
151
158
152
:::::: challenge
159
153
160
154
### Assess the software project (10 min)
161
155
162
156
Individually inspect the code and data.
163
-
Try and see if you can understand what the code is doing and how it is organised.
157
+
Try to understand what the code is doing and how it is organised.
164
158
165
-
In the shared document, write down anything that you think is not "quite right", not clear, is missing, or could be done better.
159
+
In the shared document, write down anything that you think is "not quite right", unclear, missing, or non-optimized.
166
160
167
161
::: hint
168
162
169
163
Below are some suggested questions to help you assess the code.
170
-
These are not the only criteria on which you could evaluate the code and you may find other aspects to comment on.
164
+
These are not the only criteria on which you could evaluate the code, and you may find other aspects to comment on.
171
165
172
166
- If these files were emailed to you, or sent on a chat platform, or handed to you on a memory stick, how easy would it be to find them again in 6 months, or 3 years?
173
167
- Can you understand the code? Does it make sense to you?
@@ -194,16 +188,16 @@ This is a (non-exhaustive) list of things that could be fixed/improved with our
194
188
#### File and variable naming
195
189
196
190
- the data file (`data.json`) and the R script (`my code v2.R`) could have more descriptive names
197
-
- R script (`my code v2.R`) should not contain blank spaces as it may cause problems when running the code from command line
191
+
- R script's name (`my code v2.R`) should not contain blank spaces as it may cause problems when running the code from command line
198
192
- variables (e.g. `t`, `tt`, `ttt`) should have more descriptive and meaningful names
199
193
- version control is embedded in file name (`my code v2.R`) - there are better ways of keeping track of changes to code and its different versions
200
-
- the project contains a hidden file `.DS_Store` which is local and personal config file that should not be shared and does not even make sense other than on macOS
194
+
- the project contains a hidden file `.DS_Store` which is local and personal config file that does not need to be shared and isn't used outside a Mac ecosystem
201
195
202
196
#### Code organisation and style
203
197
204
-
-fixing inconsistent use of `=` vs `<-` in the code
198
+
-fix inconsistent use of `=` vs `<-` in the code
205
199
- remove repeated code and use functions instead
206
-
- import statements should be grouped at the top
200
+
-group import statements together at the top
207
201
- commenting and uncommenting code should not be used to direct the flow of execution / type of analysis being done
208
202
- the code lacks comments, documentation and explanations
209
203
- code structure could be improved to be more modular and not one monolithic piece of code - e.g. use functions for reusable units of functionality
@@ -219,15 +213,15 @@ This is a (non-exhaustive) list of things that could be fixed/improved with our
219
213
#### Documentation
220
214
221
215
- there is no README documentation to orient the user
222
-
- there is no licence information to say how the code can be reused (which then means it cannot be reused at all)
216
+
- there is no license information to say how the code can be reused (which then means it cannot be reused at all)
223
217
- it is not clear what software dependencies the code has
224
218
- there are no installation instructions or instructions on how to run the code
225
219
226
220
:::
227
221
228
222
::::::
229
223
230
-
As you have seen from the previous exercise - there are quite a few things that can be improved with this code.
224
+
As you have seen from the previous exercise, there are quite a few things that can be improved with this code.
231
225
We will try to make this research software project a "bit better" for future use.
0 commit comments