Integrating google sheets with R

Sometimes you have to integrate data from ~google drive~, which is continuously updated, and you have to re-do some analyses, On this context try to download a file multiple time to get the different updates is a inefficient approach, instead of that you can integrate with ~google sheets~.

You will need googlesheets4 and googledrive packages

if (!require("googlesheets4")) install.packages("googlesheets4")
## Loading required package: googlesheets4
if (!require("googledrive")) install.packages("googledrive")
## Loading required package: googledrive
## 
## Attaching package: 'googledrive'
## The following objects are masked from 'package:googlesheets4':
## 
##     request_generate, request_make
library(googlesheets4)
library(ggplot2)
library(googledrive)

First, you have you provide you credential to have access to you document you can do it with gs4_auth() function, if you have not done this before a pop-up will appear asking for you credentials

gs4_auth(use_oob = F)

Then, you can use the most useful function from googlesheets4 read_sheet(), this function only needs the url or some identifier to work.

my_genes <-  read_sheet("https://docs.google.com/spreadsheets/d/1PIMILMN2kIaTcmZpZxrIUY7fJiXF2K_3ejPfeqt6wBA/edit?usp=sharing") %>% tibble::as.tibble()
## ✓ Reading from "Genes_related_with_Alzaimer".
## ✓ Range 'Genes_related_with_Alzaimer'.
## New names:
## * `` -> ...1

And finally you can do you analyses or plot inside of

my_genes2 <- head(my_genes)
ggplot(my_genes2, aes(len,symbol,color = symbol))+
        geom_point(aes(start,symbol))+
        xlab("Position")+
        ylab("SYMBOL")+
        guides(color = F)
Diego Sierra Ramírez
Diego Sierra Ramírez
Msc. in Biological Science / Data analyst

Related