# ---------------------------------------------------------------------
# AcessaExcelNoGithub_R.R
# Author: Luiz Carlos Estraviz Rodriguez
# Updated: 05/Abr/2025
# ---------------------------------------------------------------------
rm(list=ls(all=TRUE)) # Memory cleanup
gc()
# Load packages
if(!require(tidyverse))
install.packages("tidyverse")
library(tidyverse)
if(!require(rio))
install.packages("rio")
library(rio); install_formats()
# Define github URL where climate data from Piracicaba is stored
# OBS: copy the full github URL address and replace "tree" with "blob")
url_1 <- "https://github.com/FlorestaR/dados/blob/main/X_PIRACLIM/"
xls_2 <- "DadosClima_Piracicaba.xlsx"
prm_3 <- "?raw=true"
gitFile <- paste0(url_1, xls_2,prm_3)
# Imports the Excel spreadsheet from github using the rio package,
# making sure the first 8 columns become "factors" and the rest of
# the columns remain numeric. Then converts the downloaded data
# into a tibble (dataframe)
sheetName <- "DadosClima_Piracicaba"
my_col_types <- c(rep("text", 8), rep("numeric", 16))
df <- import(gitFile, which = sheetName, col_types = my_col_types)
df <- df %>% mutate(across(1:8, factor)) %>% tibble()
# Show column names and structure of the data.daframe
colnames(df)
str(df)
# Shows first lines of the dataframe
head(df)
# Creation of a simple histogram for a subgroup of years
t_max <- df %>%
filter(Ano %in% c(2022, 2023, 2024)) %>%
pull(TMAX)
hist (t_max,
main = "Temperaturas 2022-2024 - Piracicaba-SP",
xlab = "Temperaturas", ylab = "Freq.",
col = "grey",
border = "black",
freq =F,
breaks = c(0,5,10,15,20,25,30,35,40,45),
right = T,
labels = F)