Skip to content

Instantly share code, notes, and snippets.

Paul Rougieux paulrougieux

View GitHub Profile
@paulrougieux
paulrougieux / hyphen.lyx
Last active Nov 5, 2015
Hyphens are not printed when printing from the evince PDF viewer on Debian
View hyphen.lyx
#LyX 2.1 created this file. For more info see http://www.lyx.org/
\lyxformat 474
\begin_document
\begin_header
\textclass article
\use_default_options true
\begin_modules
knitr
\end_modules
\maintain_unincluded_children false
@paulrougieux
paulrougieux / countwordpersentence.R
Last active Oct 30, 2015
Count the number of words per sentence
View countwordpersentence.R
#' Separate the input text in sentences and count the number of words per sentence
#' @param blabla character vector containing a single text string.
#' @param minwordpersentence number minimum of word that a sentence should
#' have so that it is taken into account
#' @return a list countaining the number of sentence, wordcount,
#' mean number of words per sentence and total word count.
#' @export
countwordpersentence <- function(blabla, minwordpersentence = 2){
blabla <- strsplit(blabla,"\\.")[[1]]
View knitr_iris.lyx
#LyX 2.1 created this file. For more info see http://www.lyx.org/
\lyxformat 474
\begin_document
\begin_header
\textclass article
\begin_preamble
\usepackage{booktabs}
\end_preamble
\options authoryear
@paulrougieux
paulrougieux / octave.R
Last active Aug 29, 2015
Create and execute an Octave file
View octave.R
#' Create and execute an Octave file
#'
#' This function creates 2 files in the working directory:
#' \itemize{
#' \item{filename.m contains an Octave (Matlab) script}
#' \item{filename.csv contains estimation results}
#' }
#' Variables filename and
#' allitems are currently used as mustache tag variables.
#' More information on the Mustache format:
@paulrougieux
paulrougieux / dplyrsql.R
Last active Aug 29, 2015
Display SQL statement from dplyr chained operations
View dplyrsql.R
library(dplyr)
library(nycflights13)
# Create a SQLite databse
my_db <- src_sqlite("my_db.sqlite3", create = T)
flights_sqlite <- copy_to(my_db, flights,
temporary = FALSE,
indexes = list(c("year", "month", "day"),
"carrier", "tailnum"))
@paulrougieux
paulrougieux / STATA.R
Last active Aug 29, 2015
Create and execute a STATA do file passing some variables as mustache tags
View STATA.R
library(dplyr)
# Estimate a panel data model using plm and STATA
# Transmit some variables to STATA using mustache tags
# Write panel data to csv for use in STATA
write.csv(Grunfeld, path, item_, ".csv", names = FALSE, na = ".")
#' Create and execute a STATA do file
@paulrougieux
paulrougieux / list_files_mardown.R
Last active Aug 29, 2015
List of link to files in 2 level directory, useable in Markdown
View list_files_mardown.R
```{r results='asis'}
for (f in list.files()){
if(file.info(f)$isdir){
l <- c(f, paste0(f,"/",list.files(f)))
cat(paste0("* [",c(f, list.files(f)),"]","(",l,")\n"))
}
}
```
@paulrougieux
paulrougieux / FAOregioncodes.R
Last active Aug 29, 2015
FAOregioncodes for the FAOSTAT module
View FAOregioncodes.R
FAOregioncodes <- structure(list(FAOST_CODE = c(5000L,
5100L, 5101L, 5102L, 5103L, 5104L, 5105L, 5200L, 5203L, 5204L,
5206L, 5207L, 5300L, 5301L, 5302L, 5303L, 5304L, 5305L, 5400L,
5401L, 5402L, 5403L, 5404L, 5500L, 5501L, 5502L, 5503L, 5504L,
5600L, 5706L, 5801L, 5802L, 5803L, 5815L, 5817L, 5848L, 5849L),
Region = structure(c(37L, 1L, 10L, 20L, 23L, 31L, 34L, 2L,
24L, 8L, 7L, 30L, 5L, 9L, 11L, 32L, 29L, 35L, 13L, 12L, 25L,
33L, 36L, 26L, 6L, 18L, 19L, 27L, 4L, 14L, 16L, 15L, 28L, 17L,
21L, 3L, 22L),
.Label = c("Africa", "Americas", "Annex I countries"
@paulrougieux
paulrougieux / lmdisplay.R
Last active Dec 31, 2015
# Function to output latex equation based on an estimated model # The goal is to display an estimated equation in latex form with coefficients in parenthesis # Output can be used in an R Markdown file, provided the chunk option # {r, results='asis'} has been set
View lmdisplay.R
# Functions usefull to display estimated equations
# Author: Paul Rougieux
# Function to output LaTeX equation based on an estimated model
# The goal is to display an estimated equation in latex form with coefficients in parenthesis
# Output can be used in an R Markdown file, provided the chunk option
# {r, results='asis'} has been set
lmdisplay = function(model){
coefs = round(data.frame(t(summary(model)$coefficients[,1:2])),3)
You can’t perform that action at this time.