ibartomeus / traitbase

This repo manages the dynamic individual trait database www.traitbase.info via traitbaseR (https://github.com/metadevpro/traitbaser)
7 stars 1 forks source link

add_data() is problematic #4

Closed ibartomeus closed 6 years ago

ibartomeus commented 8 years ago

Ideally I wanted to add data as a pull request that I can validate and accept. In practice is not really possible.

1) a pull request is a github feature, so git2r do not helps on this. You can clone, add, but not do a pull.request.

library(git2r)
## Create a temporary directory to hold the repository
temp_path <- file.path(tempfile(pattern="traits-"), "traits")
dir.create(temp_path, recursive=TRUE)
## Clone the repository
repo <- clone("https://github.com/ibartomeus/traitdata.git", temp_path)
write.csv(dat, paste0(temp_path, "/bee_specimens.csv"), row.names = FALSE, append = TRUE)
add(repo, "bee_specimens.csv") 
commit(repo, "added data to check")
#pull request?  
#need to delete temporal dir? #unink()

2) but github has a API and rgithub can use it. This may allow to fork, pull request for github users, but need log in, and it's not worthy to follow that direction, I think.

install_github("cscheid/rgithub")
library("github")
create.fork(owner = "ibartomeus", repo = "traitbase")
create.pull.request(owner = "ibartomeus", repo = "traitbase", 
                    content = "{
                    'title': 'Amazing new feature',
                    'body': 'Please pull this in!',
                    'head': 'octocat:new-feature',
                    'base': 'master'
                    }")

3) Alternatively I wanted to send the .csv somewhere, to catch it later. WITHOUT having to log in and in a place with only write access. google forms seems ideal for this. But is not because you can only add a row at a time and its bloody slow, so for data with 100 rows will take an hour :(

library(googleformr)
url <- "https://docs.google.com/forms/d/1ng31vOADdfc-birlEa8mlogR2PI1Zi0-yzJX3HGx_Us" 
new_post_to_form <- gformr(url)
new_post_to_form(c("1", "2"))

4) google sheets then? Well, sheets has to public and people can write/edit at will... which may be dangerous.

library(googlesheets) extract_key_from_url("https://docs.google.com/spreadsheets/d/1fpnI4eqShShFymmyayIfWUOkiNsGulVXhAT3-KhSa-g")
test <- gs_key("1fpnI4eqShShFymmyayIfWUOkiNsGulVXhAT3-KhSa-g")
gs_edit_cells(test, ws = "temp_data", input = head(iris), trim = TRUE)
for (i in 2:6) {
    gs_add_row(test, ws = "temp_data", input = iris[i, ])
    Sys.sleep(0.3)
}
iris %>%
    head(5) %>%
    write.csv("iris.csv", row.names = FALSE)
iris_ss <- gs_upload("iris.csv")

5) The option what I like best after all presented caveats is send me an email with the data. This may be ugly, but why not?

library(sendmailR)
Server<-list(smtpServer="ASPMX.L.GOOGLE.COM")
Sender <- sprintf("<prefierobollitos@gmail.com>","nacho")
Subj <- "data!"
Email <- "contents/body of email"
Recipient<-sprintf("<nacho.bartomeus@gmail.com>")
Doc1<-"/process.R"
Object1<-mime_part(Doc1,name="process.R")
Email_Att<- list(Email,Object1)
sendmail(from=Sender, to=Recipient, subject=Subj,
         msg=Email_Att, control=Server)
#or
#mailR
library(mailR)
sender <- "prefierobollitos@gmail.com" # Replace with a valid address
recipients <- c("nacho.bartomeus@gmail.com") # Replace with one or more valid addresses
email <- send.mail(from = sender,
                   to = recipients,
                   subject="Subject of the email",
                   body = "Body of the email",
                   smtp = list(host.name = "aspmx.l.google.com", port = 25),
                   authenticate = FALSE,
                   send = FALSE)
email$send()