Skip to content

Instantly share code, notes, and snippets.

François Briatte briatte

Block or report user

Report or block briatte

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View sample.r
# change of PRNG in R >= 3.6.0
# use former PRNG
RNGkind(sample.kind = "Rounding")
# use new/fixed PRNG
RNGkind(sample.kind = "default")
# see ?Random for details
View disc2019.R
# Load data
# Get a SpatialLinesDataFrame of countries borders
nuts0.contig.spdf <- getBorders(nuts0.spdf)
# Get the GDP per capita
nuts0.df$gdpcap <- nuts0.df$gdppps2008/nuts0.df$pop2008*1000000
View 0-download-all-ergm-sources.R
## download all `ergm` sources from v3.0-1 to today
d <- "ergm-sources"
dir.create(d, showWarnings = FALSE)
# current source
briatte / gist:ad24bb323d2603dbdd3af35086147c83
Created May 18, 2019 — forked from conormm/
R to Python: Data wrangling with dplyr and pandas
View gist:ad24bb323d2603dbdd3af35086147c83
R to python useful data wrangling snippets
The dplyr package in R makes data wrangling significantly easier.
The beauty of dplyr is that, by design, the options available are limited.
Specifically, a set of key verbs form the core of the package.
Using these verbs you can solve a wide range of data problems effectively in a shorter timeframe.
Whilse transitioning to Python I have greatly missed the ease with which I can think through and solve problems using dplyr in R.
The purpose of this document is to demonstrate how to execute the key dplyr verbs when manipulating data using Python (with the pandas package).
dplyr is organised around six key verbs
briatte / pairs_plot.R
Created May 8, 2019 — forked from expersso/pairs_plot.R
Create scatterplot matrix using the tidyverse
View pairs_plot.R
plot_pair <- function(data, x, y) {
ggplot(data, aes_string(x = x, y = y, color = "Species", shape = "Species")) +
geom_point() +
scale_color_brewer(palette = "Dark2") +
theme(legend.position = "none", plot.title = element_text(size = 7)) +
labs(x = NULL, y = NULL, title = paste0(y, " ~ ", x))
input str500 x
"-73.974651 40.73868,-73.973391 40.73897,-73.97323 40.73955,-73.97298 40.7415304,-73.97247 40.7423406,-73.97229 40.7428504,-73.97213 40.74338,-73.971871 40.7440804,-73.97141 40.7446706,-73.97103 40.7455605,-73.970301 40.7465204,-73.96929 40.7472"
"-73.970301 40.7465204,-73.96929 40.7472"
// keep only the first pair of coordinates
replace x = regexr(x, ",.*", "")
// split by space, converting to numeric
View session_info.r
# ==============================================================================
# A script to deal with package dependencies that will
# - detach all packages except base ones
# - install its own package dependencies
# - look for session_info.txt and parse it for packages
# - ensure the packages are installed and up to date
briatte / label_facets_ggplot2.R
Created Jan 9, 2019 — forked from padpadpadpad/label_facets_ggplot2.R
function to label facets with letters in ggplot2
View label_facets_ggplot2.R
# load package
# write function
label_facets <- function(string){
len <- length(string)
string = paste('(', letters[1:len], ') ', string, sep = '')
View mathjax.html
<script src="" async></script>
<script type="text/x-mathjax-config">
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
briatte / .htaccess
Created Jan 6, 2019
Show RSS feeds on a Web page via pure JavaScript, incl. code to bypass Chrome's CORS policy.
View .htaccess
# enable CORS policy
<IfModule mod_rewrite.c>
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
Header add Access-Control-Allow-Headers: "Content-Type"
RewriteEngine on
RewriteBase /
You can’t perform that action at this time.