Skip to content

Instantly share code, notes, and snippets.

View ikashnitsky's full-sized avatar

Ilya Kashnitsky ikashnitsky

View GitHub Profile
@ikashnitsky
ikashnitsky / fun-fread-local-hmd.R
Last active April 11, 2025 09:51
Handy functions to quickly load locally stored HMD files -- get the zip from https://www.mortality.org/cgi-bin/hmd/hmd_download.php
#===============================================================================
# 2021-02-23 -- local hmd UPD 2025-04-11
# Function to read in a whole local HMD folder
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#===============================================================================
# a function to read ONE file
fread_hmd <- function(x) x %>%
data.table::fread(skip = 2, na.strings = ".") %>%
mutate(Age = Age %>% str_remove("\\+") %>% as.integer()) %>%
@ikashnitsky
ikashnitsky / get-all-sjr-data.r
Created September 22, 2018 11:58
Get all SCImago Journal & Country Rank data (script version of sjrdata package)
################################################################################
#
# bibliometrics 2018-09-22
# SJR data -- load and combine all files -- GIST
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#
################################################################################
library(tidyverse)
library(janitor)
@ikashnitsky
ikashnitsky / links.md
Last active March 7, 2025 09:16
Links for the talk at RFF R/py club meeting
#===============================================================================
# 2019-07-19-- ikashnitsky.github.io
# Reproduce Figure 2 from http://doi.org/10.1007/s10708-018-9953-5
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#===============================================================================
library(tidyverse)
library(hrbrthemes); import_roboto_condensed()
# the data as tribble
@ikashnitsky
ikashnitsky / data.csv
Last active December 18, 2024 13:44
Code accompanying Rotate the Damn Plot post -- https://ikashnitsky.phd/2024/rotate-damn-plot/
0.9505599562960936 7.373295920141045
1.0986069379950836 7.328921556455017
1.2791586998087952 7.3965756996349725
1.4164162797049977 7.896948176106876
1.5681507784758253 7.501837550594721
1.992078667030866 7.42089841325023
2.1416279704998624 7.585483350301706
2.2817536192297174 7.757505400908842
2.4356733133023756 7.802699212833056
2.624146408085222 7.653956941719848
@ikashnitsky
ikashnitsky / top-50-demographers.R
Last active January 3, 2024 15:13
Demographic Hall of Fame – authors who published most papers in 10 leading demographic journals
auth_50 %>%
ggplot(aes(avg_cit, n_papers, color = avg_age_of_papers))+
geom_vline(xintercept = 0, size = 2, color = "#04444499")+
geom_point(size = 2)+
geom_text(
aes(label = author_abbr, size = n_papers),
hjust = c(-.1, 1.1) %>% rep(25),
vjust = c(-.05, 1.05) %>% rep(25),
fontface = 2,
alpha = .75
@ikashnitsky
ikashnitsky / convert_pdf_to_png.R
Created December 21, 2023 16:36
R function to convert all PDFs in a directory into PNGs
#===============================================================================
# 2023-12-21 -- misc
# convert pdf to png
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com, @ikashnitsky
#===============================================================================
#' @description A function to convert all PDFs in a directory into PNGs
#' @param dir_pdfs character. A character string with a path to the directory containing PDFs to convert
#' @param output_dir character. An optional parameter to specify the output directory for the converted PNGs. Defaults to `"/png"`, which creates a sub-directory `png` in the specified above `dir_pdfs` directory. Can be any location on the machine, one useful place may be something with all the temporary stuff like `"~/Downloads"`. Important: don't leave trailing slashes in the parameters.
@ikashnitsky
ikashnitsky / asian-restaurants-dk.R
Created November 6, 2023 11:55
Map all OSM restaurant of Denmark and highlight Asian cuisine ones calculate % in regions
#===============================================================================
# 2023-11-06 -- 30DayMapChallenge
# ASIA -- restaurants in Denmark
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com, @ikashnitsky.phd
#===============================================================================
library(tidyverse)
library(magrittr)
library(osmdata)
library(eurostat)
@ikashnitsky
ikashnitsky / publons-country.R
Last active November 3, 2023 15:29
Map the country data of Publons (data from https://publons.com/country, manual export on 2021-01-07) – https://twitter.com/ikashnitsky/status/1347325289496502272
#===============================================================================
# 2021-01-07 -- twitter
# Visualize Publons country data
# https://publons.com/country
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#===============================================================================
library(tidyverse)
library(magrittr)
library(sf)
@ikashnitsky
ikashnitsky / example-smd.R
Last active April 28, 2023 12:31
Scholarly Migration Database launch meeting -- examples
#===============================================================================
# 2023-04-12 -- SMD lightning talk
# Usecase of SMD
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com, @ikashnitsky
#===============================================================================
library(tidyverse)
library(magrittr)
library(prismatic)
library(janitor)