Skip to content

Instantly share code, notes, and snippets.

View oousmane's full-sized avatar
🎯
Focusing

Ousmane Ouedraogo oousmane

🎯
Focusing
View GitHub Profile
@oousmane
oousmane / write_fwf.R
Created May 3, 2023 11:39 — forked from haozhu233/write_fwf.R
Generate fixed width file in R
#' Generate fixed width file in R
#' @description This simple function creates fixed width file with no
#' extra dependencies.
#' @param justify "l", "r" or something like "lrl" for left, right, left.
#' @examples dt <- data.frame(a = 1:3, b = NA, c = c('a', 'b', 'c'))
#' write_fwf(dt, "test.txt", width = c(4, 4, 3))
#' @export
write_fwf = function(dt, file, width,
justify = "l", replace_na = "NA") {
fct_col = which(sapply(dt, is.factor))
@oousmane
oousmane / terra-idrisi-raster-plot.R
Last active April 8, 2023 23:45
This code provide a way to read in IDRISI Raster Format with terra and plot with ggplot2
library(terra) # Spatial Data Analysis
library(tidyterra) # 'tidyverse' Methods and 'ggplot2' Helpers for 'terra'
library(ggplot2) # For Data Visualisations Using the Grammar of Graphics
library(rgeoboundaries) # For Political Administrative Boundaries
library(ggspatial) # Spatial Data Framework for ggplot2
library(ggtext) # Improved Text Rendering Support for 'ggplot2'
library(ggsflabel) # for spatial labeling
x <- terra::rast(x = "/Volumes/OUSMANE/exo_BSD/semis_fin_07/sem0173.rst")
y <- classify(x,c(0,1,2,3,4,5,6,7,8))