-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_no_gdrive.R
59 lines (34 loc) · 1.47 KB
/
upload_no_gdrive.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Como upar planilhas automaticamente no Google Drive
library(googledrive)
#fazendo uma planilha de teste para upar no drive:
teste_gdrive <- c("a, b", "1,2")
teste_gdrive_df <- read.csv(text = teste_gdrive, strip.white = TRUE)
View(teste_gdrive_df)
#autenticação no google drive:
drive_find(n_max=10) #aqui tu deve responder 2 para abrir o browse e tu logar no gdrive
#Salve a planilha em csv:
setwd("C:\\Users\\jvoig\\OneDrive\\Documentos\\Colab\\COLAB\\templates")
#Salvar com os seguintes parâmetros para que não dê erro para a exportação para spreadsheet:
write.table(teste_gdrive_df , file="teste_gdrive_df.csv",
sep=",", row.names=F, na="", quote = T) #aqui eu salvei com o write.table, mas poderia ser o data.table::fwrite()
#agora, ele vai buscar no diretório já setado o arquivo para upload:
drive_upload(
"teste_gdrive_df.csv",
path="~/TB/2018/",
name = "teste2",
type = "spreadsheet")
#path é o caminho onde o arquivo será guardado, o ~ é o "meu drive" e dai você especifica o
#caminho ;)
#Obs: alternativa para salvar como Excel (as vezes é melhor)
library(xlsx)
write.xlsx(as.data.frame(objeto),
file="objeto.xlsx", sheetName="objeto",
col.names=TRUE, row.names=FALSE, append=FALSE, showNA=FALSE)
## Download no Drive
library(googlesheets)
#Autenticação:
gs_ls()
#Importando:
contatos_sheet <- gs_title("TDP_Contatos_produção_nova")
#Atribuindo o df a um objeto:
contatos_tdp <- gs_read(contatos_sheet)