:= lets you assign variables as part of larger expressions.
Example:
| import requests | |
| import pandas as pd | |
| import altair as alt | |
| from typing import List, Tuple | |
| def download_comments(repo: str, user: str) -> List[str]: | |
| url = f"https://api.github.com/repos/{user}/{repo}/issues/comments" | |
| res = requests.get(url) | |
| if res.ok: |
| library(tidyverse) | |
| ## testing overall incidence of intransitivity | |
| # number of intransitive fish in each experiment per the results | |
| intransitive <- c(9, 6, 6) | |
| # total number of fish in each experiment | |
| total <- c(10, 11, 23) + intransitive |
| # edited from https://github.com/aschinchon/travelling-salesman-portrait/blob/master/frankenstein_TSP.R | |
| library(imager) | |
| library(dplyr) | |
| library(ggplot2) | |
| library(scales) | |
| library(TSP) | |
| urlfile <- "https://www.dropbox.com/s/4td7zbqohyw0f3g/creepy.jpg?dl=0" |
| require(tidyverse) | |
| # computes things you want to know across the entire trial | |
| do_it <- function(x) { | |
| name <- x$filename[1] | |
| fish_name <- name %>% stringr::str_match(pattern = "_S[a-z]+?_([A-Za-z]+)_") %>% as.vector %>% .[2] | |
| temp <- x %>% | |
| mutate(time_zone = lead(time) - time) %>% | |
| group_by(code) %>% |
| # the goal: | |
| ## download the animation | |
| ## use ffmpeg to make it playable | |
| ## change the speed of the animation | |
| ## randomally change the speed of the animation | |
| ## concatenate multiple speeds together | |
| # make a directory to keep things tidy | |
| mkdir create_video | |
| cd create_video |
| #!/usr/bin/env bash | |
| # this script downloads an example animation from the internet and creates looped version of the animation that you could then use in a mate choice study | |
| # the advantage of the script as opposed to doing this in something like iMovie: | |
| ### time. On my computer this script takes <30 seconds to execute. Doing this in iMovie could easily take half an hour. | |
| ### repeatability. I can send this script to you and you can make the video yourself. | |
| ### easy to remake videos when you make a mistake | |
| ### easy to keep track of what you've done. A plain text script like this allows you do _version control_ your work, allowing you to revert to a previous version and always know when you changed parts of your code | |
| # make a directory to keep things tidy |
| data_frame(x=1:10) %>% | |
| mutate( | |
| # x2 = x*2, | |
| x3 = x*3) %>% | |
| filter(x>5) |
| library(ggplot2) | |
| library(cowplot) # github version | |
| # create dataframe with x and y with different ranges | |
| df <- data.frame(x = rnorm(20, mean = 5, sd = 2), y = rnorm(20, mean = 20, sd = 5)) | |
| # create scatterplot | |
| p <- ggplot(df, aes(x = x, y = y)) + | |
| geom_point() |
| df <- read_csv("http://datadryad.org/bitstream/handle/10255/dryad.152300/forDryad.csv?sequence=1") | |
| df %<>% unite(uni, source, target) | |
| edges <- df %>% | |
| group_by(uni) %>% | |
| count %>% | |
| separate(col = "uni", into = c("source", "target"), sep = "_") | |
| edges <- rename(edges, number = n) | |
| net <-graph_from_data_frame(edges) |