Skip to content

Conversation

@jacottemonroe
Copy link
Owner

Most of the modifications made were to add some links to other tutorials, otherwise fixing some typos, updating tutorial numbering, ...

index.Rmd Outdated

# [WUR Geoscripting](https://geoscripting-wur.github.io/) <img src="https://www.wur.nl/upload/854757ab-168f-46d7-b415-f8b501eebaa5_WUR_RGB_standard_2021-site.svg" alt="WUR logo" style="height: 35px;"/>

# Week 1, Tutorial 3: Intro to functions and refresher on R
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the tutorial numbering to make it more flexible. Also, the tutorial could be adapted it a bit since this is no longer a "refresher" on R. I didn't want to change it in case it created problems elsewhere. Suggestion: "Intro to functions and handling spatial data in R".

Scripting with *R* to handle spatial problems requires a core set of basic *R* skills. To prepare you well for the coming weeks, we've summarized what we think are important skills for geoscripting below.

```{block type="alert alert-info"}
**Note** that this tutorial uses the basic programming structure with lists, strings, and more. For a refresher on these elements click [here](https://geoscripting-wur.github.io/RPythonBasics/).
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to put a reference to the R and Python Basics tutorial in case students skipped it. I am not 100% sure how hyperlinks work in Rmd, I tried to look at other scripts for reference, but my links could have errors...

On another note, it could be nice to have an additional section on getting started with RStudio. Going over the RStudio structure, the console, ... It is probably that some students have never used any IDE before.


* `list.files()`: to list files in a directory.
* `glob2rx()`: to select files using a wildcard. Note: if you know regular expressions, you do not need that function. But most people are more comfortable working with wildcards.
* `glob2rx()`: to select files using a wildcard. Note: if you know regular expressions, you do not need that function. But most people are more comfortable working with wildcards. For a list of wildcards click [here](../Intro2Linux/index.html#file-manipulation).
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added link to tutorial with table of wildcards. Check that the link works.

- Indentation (like in Python: use spaces or tab to indent code in functions or loops etc.).
- Consistent use of the assignment operator: either `<-` or `=` in all your code. The former is used by core R and allows assigning in function calls, the latter is shorter and consistent with most other programming languages.
- Consistent placement of curly braces.
* [Make your own packages](#__optional__Writing_packages_).
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link is not working but I am not sure how to fix it. Goes to the start of the tutorial instead of going to the section on writing packages.

- Consistent use of the assignment operator: either `<-` or `=` in all your code. The former is used by core R and allows assigning in function calls, the latter is shorter and consistent with most other programming languages.
- Consistent placement of curly braces.
* [Make your own packages](#__optional__Writing_packages_).
* Keep a similar [directory structure](../RProjectManagement/index.html) across your projects.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is unclear which part of tutorial 1 is relevant for keeping a consistent directory structure. Perhaps the link is not necessary.

index.Rmd Outdated
- Consistent placement of curly braces.
* [Make your own packages](#__optional__Writing_packages_).
* Keep a similar [directory structure](../RProjectManagement/index.html) across your projects.
* Use [version control](../RProjectManagement/index.html) to develop/maintain your projects and packages.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link currently brings students to the start of tutorial 1. Could be more helpful to bring them to the version control section directly. Check that link works.

* Use [version control](../RProjectManagement/index.html#version-control) to develop/maintain your projects and packages.
* Never place `rm(list = ls())` anywhere in your script. If you do so, you may [find your computer set on fire](https://www.tidyverse.org/blog/2017/12/workflow-vs-script/).
* Use relative file paths and never use `setwd()`. Do press the button below every time you open a script, and assume everyone else will do that too.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image below of the demo for setting the working directory is from a Mac. However, most students will be using Windows version of RStudio. Could be more helpful to have a screenshot of how to set the working directory from Windows. See attachment.
RStudio_screenshot


### Object classes and Control flow
You have seen in a previous tutorial already that every variable in your R working environment belongs to a class. You can take advantage of that, using control flow, to make your functions more flexible.
You have seen in a [previous tutorial](../RPythonBasics/index.html/#data-types) already that every variable in your R working environment belongs to a class. You can take advantage of that, using control flow, to make your functions more flexible.
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if link works.

class(c)
```

Here we used the function `rast` from the Terra package to create an object of class `SpatRaster`. `SpatRaster` is a class for rasters (or matrices) that comprise the necessary elements for spatial data. With Terra and `SpatRaster`, complex spatial data will be processed more efficiently by using specifically tailored functions for `SpatRaster`. This will be studied further in [another tutorial](../IntroToRaster/index.html).
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code above uses the Terra package and the SpatRaster class. I added a short description for context even though this will be covered in later tutorials. However, this paragraph is not necessary if we want to make the tutorial shorter.

index.Rmd Outdated
# but some elements of the list are impredictibly corrupted, so the list looks as follows
b <- a
c <- NA
list <- list(a, b, c)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling this variable "list" could create confusion for students, especially when the function "list()" is also being used a lot in this chunk of code. To show exemplary scripting habits, changed the variable name to something a bit more descriptive to facilitate interpretation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants