class: title-slide count: false .title[ # Cheat Sheets ] .subtitle[ ## Open Science Tools ] .author[ ### Claudio Zandonella & Davide Massidda ] .institute[ ] --- ## RStudio Keyboard Shortcuts .pull-left-50[ <table class="table" style="font-size: 15px; width: auto !important; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;"> Command </th> <th style="text-align:left;"> Windows & Linux </th> <th style="text-align:left;"> MacOS </th> </tr> </thead> <tbody> <tr grouplength="4"><td colspan="3" style="border-bottom: 1px solid;"><strong>Basic</strong></td></tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Run current line </td> <td style="text-align:left;"> Ctrl+Enter </td> <td style="text-align:left;"> Cmd+Return </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Jump to Word </td> <td style="text-align:left;"> Ctrl+Left/Right </td> <td style="text-align:left;"> Option+Left/Right </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Jump to Start/End </td> <td style="text-align:left;"> Ctrl+Home/End </td> <td style="text-align:left;"> Cmd+Home/End </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Delete Line </td> <td style="text-align:left;"> Ctrl+D </td> <td style="text-align:left;"> Cmd+D </td> </tr> <tr grouplength="8"><td colspan="3" style="border-bottom: 1px solid;"><strong>Life Hack</strong></td></tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Insert assignment operator </td> <td style="text-align:left;"> Alt+- </td> <td style="text-align:left;"> Option+- </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Insert pipe operator </td> <td style="text-align:left;"> Ctrl+Shift+M </td> <td style="text-align:left;"> Cmd+Shift+M </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Comment/uncomment </td> <td style="text-align:left;"> Ctrl+Shift+C </td> <td style="text-align:left;"> Cmd+Shift+C </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Reflow Comment </td> <td style="text-align:left;"> Ctrl+Shift+/ </td> <td style="text-align:left;"> Cmd+Shift+/ </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Reformat Selection </td> <td style="text-align:left;"> Ctrl+Shift+A </td> <td style="text-align:left;"> Cmd+Shift+A </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Find in Files </td> <td style="text-align:left;"> Ctrl+Shift+F </td> <td style="text-align:left;"> Cmd+Shift+F </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Show help for function at cursor </td> <td style="text-align:left;"> F1 </td> <td style="text-align:left;"> F1 </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Check Spelling </td> <td style="text-align:left;"> F7 </td> <td style="text-align:left;"> F7 </td> </tr> </tbody> </table> ] .pull-right-50[ <table class="table" style="font-size: 15px; width: auto !important; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;"> Command </th> <th style="text-align:left;"> Windows & Linux </th> <th style="text-align:left;"> MacOS </th> </tr> </thead> <tbody> <tr grouplength="4"><td colspan="3" style="border-bottom: 1px solid;"><strong>Pro Tricks</strong></td></tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Move Lines Up/Down </td> <td style="text-align:left;"> Alt+Up/Down </td> <td style="text-align:left;"> Option+Up/Down </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Copy Lines Up/Down </td> <td style="text-align:left;"> Shift+Alt+Up/Down </td> <td style="text-align:left;"> Cmd+Option+Up/Down </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Add Cursor Above/below </td> <td style="text-align:left;"> Ctrl+Alt+Up/Down </td> <td style="text-align:left;"> Ctrl+Option+Up/Down </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Add Cursor Selection </td> <td style="text-align:left;"> Alt+mouse selction </td> <td style="text-align:left;"> Option+mouse selction </td> </tr> <tr grouplength="2"><td colspan="3" style="border-bottom: 1px solid;"><strong>RMarkdown</strong></td></tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Knit Document </td> <td style="text-align:left;"> Ctrl+Shift+K </td> <td style="text-align:left;"> Cmd+Shift+K </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Insert R chunk </td> <td style="text-align:left;"> Ctrl+Alt+I </td> <td style="text-align:left;"> Command+Option+I </td> </tr> <tr grouplength="4"><td colspan="3" style="border-bottom: 1px solid;"><strong>Devtools</strong></td></tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Load All </td> <td style="text-align:left;"> Ctrl+Shift+L </td> <td style="text-align:left;"> Cmd+Shift+L </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Test Package </td> <td style="text-align:left;"> Ctrl+Shift+T </td> <td style="text-align:left;"> Cmd+Shift+T </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Document Package </td> <td style="text-align:left;"> Ctrl+Shift+D </td> <td style="text-align:left;"> Cmd+Shift+D </td> </tr> <tr> <td style="text-align:left;padding-left: 2em;" indentlevel="1"> Insert Roxygen Skeleton </td> <td style="text-align:left;"> Ctrl+Alt+Shift+R </td> <td style="text-align:left;"> Cmd+Option+Shift+R </td> </tr> </tbody> </table> ] --- ## Bash Cheatsheet .pull-left-70[ .code-size-12[ ```bash #---- Navigating ----# pwd # Print working directory cd <directory> # Change directory ls <directory> # List files -l # Long list with details -a # List also hidden files and directories -h # Return file size in readable units #---- Modifying ----# mkdir <directory> # Create directory touch <file> # Create file mv <source><dest> # Move (or rename) file or directory cp <source><dest> # Copy file -r # For directories rm <file> # Remove file rmdir <directory> # Remove directory #----- Other -----# echo <message> # Print message in console cat <file> # Print file in console less <file> # Open file in a screen ``` ] ] --- ## Git Cheatsheet .move-up-30[ .pull-left-50[ .code-small[ ```bash #---- Configure Settings ----# git config --list # Check configuration settings git config --global user.name "<My Name>" # Configure username git config --global user.email "<user@email.com>" # Configure email git config --global merge.conflictstyle diff3 # Configure conflict style #---- Initialize Git Repo ----# git init <path> # Initialize local repository git clone <repository-URL> # Clone remote repository #---- Tracking Files ----# git status # Check repository status # Staging git add <files> # Add selected files to staging area git add --all # Add all files to staging area git rm --cached <file> # Remove selected files from staging area git reset # Remove all files from staging area # Commit git commit # Create commit # Options -a # Commit all changes of tracked files -m "<message>" # Inline commit message git log # Get commit history git log --oneline # Get commit history (compact) ``` ] ] .pull-right-50[ .code-small[ ```bash git diff # Changes since the last commit git diff <commit-ID> # Changes since a specified commit git diff <commit-ID-A> <commit-ID-B> # Changes from commit-A to commit-B. git checkout <commit-ID> # Point HEAD to specific commit/branch git revert <commit-ID> # Undo commit (forward-way) git reset <commit-ID> # Undo commit (disruptive-way) #---- Collaboration ----# git remote -v # List remote (verbose) git remote add <name> <url> # Add remote git pull <remote-name> <branch-name> # Pull commits from remote git push <remote-name> <branch-name> # Push commit to remote -u # Set upstream remote branch git branch --set-upstream-to="<remote/branch>" # Set upstream remote branch #---- Branching ----# git branch # List branches git branch -vv # List branches (verbose) git branch -vvr # List remote branches (verbose) git branch <branch-name> # Create new branch git checkout -b <new-branch-name> # Create and move to new branch git merge <branch-name> # Merge target branch git merge --abort # Abort merge git branch -d <branch-name> # Delete local Branch git push <remote-name> --delete <branch-name> # Delete remote Branch ``` ] ] ] --- .pull-left-50[ ## `targets` Cheatsheet .code-size-12[ ```r # Define targets tar_target(<target_name>, <expression>) tar_target(<target_name>, <path-to-file>, format = "file") tarchetypes::tar_render( <target_name>, <path-to-document> ) # Check pipeline tar_manifest() tar_visnetwork() # Run analysis tar_make() # Load Results tar_read() tar_load() ``` ] ] .pull-right-50[ ## `renv` Cheatsheet .code-size-12[ ```r # Initialize project init() # Install package install.packages() # Capture dependencies snapshot() # Restore dependencies restore() ``` ] ] --- ## Docker Cheatsheet .pull-left-50[ .code-small[ ```bash #---- Images ----# docker build -t <name-image>:<tag> . # Build an image from Dockerfile docker images # List all images docker image ls # List all images docker image rm <id-image> # Remove Image #---- Container ----# docker run --name <container-name> <image>:<tag> # Run a container from an Image # Other flags and options --rm # Remove at exit -it # Interactive terminal -d # Detached mode -v <host-path>:<container-path> # Attach a volume or bind mount -e <name>=<value> # Define environment variable -p <host-port>:<container-port> # Map port docker ps -a # List all containers docker container ls -a # List all containers docker stop <container-name> # Stop container docker start <container-name> # Start container docker rm <container-name> # Remove container docker cp <container-name>:<path> <host-path> # Copy from container to host docker cp <host-path> <container-name>:<path> # Copy from host to container docker exec -it <name-container> bin/bash # Connect to container bin/bash ``` ] ] .pull-right-50[ .code-small[ ```bash #---- Volumes ----# docker volume create <name-volume> # Create named volume docker volume ls # List all volumes docker volume rm <volume id> # Remove volume #---- Docker Compose ----# docker-compose up # Start service docker-compose down # Stop service #---- Docker Hub ----# docker pull <username>/<name-repo>:<tag> # Pull image docker push <username>/<name-repo> # Push image docker login --username=<username> --email=<email@com> # Login docker tag <image-id> <username>/<name-repo>:<tag> # Tag image for repository ``` ] ] --- class: inverse, center # God Progammer Mode Achieved! <img src="images/exercises/stallman.png" width="40%" style="display: block; margin: auto;" />