From e9d33972a3169e4d19b339a703e05e7cb15bda50 Mon Sep 17 00:00:00 2001 From: SeBassTian23 Date: Thu, 27 Apr 2017 13:29:39 -0400 Subject: [PATCH] Raw Data can be accessed now too, replacing print with cat --- R/createDataframe.R | 6 +++--- R/getProject.R | 34 ++++++++++------------------------ R/getProjectData.R | 15 ++++++++------- R/getProjectInfo.R | 8 ++++---- R/login.R | 10 +++++----- R/logout.R | 4 ++-- README.md | 4 ++++ 7 files changed, 36 insertions(+), 45 deletions(-) diff --git a/R/createDataframe.R b/R/createDataframe.R index 2c24fc6..3b8da1c 100644 --- a/R/createDataframe.R +++ b/R/createDataframe.R @@ -14,10 +14,10 @@ createDataframe <- function(project_info="", project_data =""){ if(!is.null(project_info) && !is.null(project_data)){ # Print Project data receival information - print("Project data received, generating data frame.") + cat("Project data received, generating data frame.\n") # Exclusion list - ToExclude <- c("protocol_number","protocol_id","id","protocol_name","baseline_values","chlorophyll_spad_calibration","averages","data_raw","baseline_sample","HTML","Macro","GraphType","time","time_offset","get_ir_baseline","get_blank_cal","get_userdef0","get_userdef1","get_userdef2","get_userdef3","get_userdef4","get_userdef5","get_userdef6","get_userdef7","get_userdef8","get_userdef9","get_userdef10","get_userdef11","get_userdef12","get_userdef13","get_userdef14","get_userdef15","get_userdef16","get_userdef17","get_userdef18","get_userdef19","get_userdef20","r","g","b","recall","messages","order") + ToExclude <- c("protocol_number","protocol_id","id","protocol_name","baseline_values","chlorophyll_spad_calibration","averages","baseline_sample","HTML","Macro","GraphType","time","time_offset","get_ir_baseline","get_blank_cal","get_userdef0","get_userdef1","get_userdef2","get_userdef3","get_userdef4","get_userdef5","get_userdef6","get_userdef7","get_userdef8","get_userdef9","get_userdef10","get_userdef11","get_userdef12","get_userdef13","get_userdef14","get_userdef15","get_userdef16","get_userdef17","get_userdef18","get_userdef19","get_userdef20","r","g","b","recall","messages","order") # Since we have all the information ready # now it is time to preprocess the data @@ -267,7 +267,7 @@ createDataframe <- function(project_info="", project_data =""){ return(dfs) } else{ - print("Warning: Missing objects") + cat("Warning: Missing objects\n") return(NULL) } } diff --git a/R/getProject.R b/R/getProject.R index e838709..2a45a02 100644 --- a/R/getProject.R +++ b/R/getProject.R @@ -3,50 +3,36 @@ #' This function allows you to receive data from PhotosynQ and convert it into a data frame. #' @param email Your email address you use to login #' @param projectID The ID of your Project (Just copy the Project ID from the project page or your user page) -#' @param rawTraces Include the raw traces for each measurement (increases data size significantly!) +#' @param processedData Receive the processed data when set to TRUE, receive raw Data when set to FALSE. (raw data will increases data size significantly!) +#' @param rawTraces Adds raw traces to processed data. It is ignored when processedData is set to TRUE. (increases data size significantly!) #' @keywords Project Data #' @export #' @examples #' getProject("john.doe@domain.com",1566,FALSE) -getProject <- function(email="", projectID="", rawTraces = FALSE){ +getProject <- function(email="", projectID="", processedData = TRUE, rawTraces = FALSE){ if(email !="" && projectID != ""){ login <- PhotosynQ::login(email) - - # Print a welcome statement - print(paste("Successfully signed in as:", login$name, sep=" ")) - + if(!is.null(login)){ project_info <- PhotosynQ::getProjectInfo(login$email, login$token, projectID) - # Print Project name - print(paste("Project:", project_info$name, sep=" ")) - if(!is.null(project_info)){ - project_data <- PhotosynQ::getProjectData(login$email, login$token, projectID, rawTraces) + # Print Project name + cat(paste("Project:", project_info$name, "\n", sep=" ")) + + project_data <- PhotosynQ::getProjectData(login$email, login$token, projectID, processedData, TRUE) if(!is.null(project_data)){ dl <- createDataframe(project_info,project_data) + cat("Done\n") return(dl) - } - else { - print("Warning: Project Data download failed.") - return(NULL) - } - } - else { - print("Warning: Project does not exist.") - return(NULL) } } - else { - print("Warning: Login failed.") - return(NULL) - } } else { - print("You have to supply email, password and project ID") + cat("You have to supply email, password and project ID\n") return(NULL) } } \ No newline at end of file diff --git a/R/getProjectData.R b/R/getProjectData.R index 0521cbf..23e3e12 100644 --- a/R/getProjectData.R +++ b/R/getProjectData.R @@ -5,23 +5,24 @@ #' @param email Your email address you use to login #' @param token Your login token from the login function #' @param projectID The ID of your Project (Just copy the Project ID from the project page or your user page) -#' @param rawTraces Include the raw traces for each measurement (increases data size significantly!) +#' @param processedData Receive the processed data when set to TRUE, receive raw Data when set to FALSE. (raw data will increases data size significantly!) +#' @param rawTraces Adds raw traces to processed data. It is ignored when processedData is set to TRUE. (increases data size significantly!) #' @keywords Project Data #' @export #' @examples #' getProjectData("john.doe@domain.com","A67DHsajjshda78",1566, FALSE) -getProjectData <- function(email="", token="", projectID="", rawTraces = FALSE){ +getProjectData <- function(email="", token="", projectID="", processedData = TRUE, rawTraces = FALSE){ if(email !="" && token != "" && projectID != ""){ httrFound <- require("httr",quietly = TRUE, warn.conflicts = FALSE, character.only = TRUE) if(!httrFound){ install.packages("httr") library("httr",quietly = TRUE, warn.conflicts = FALSE, character.only = TRUE) } - url <- paste("https://photosynq.org/api/v3/projects/",toString(projectID),"/data.json?user_email=",email,"&user_token=",token,"&upd=true&include_raw_data=",rawTraces, sep="") + url <- paste("https://photosynq.org/api/v3/projects/",toString(projectID),"/data.json?user_email=",email,"&user_token=",token,"&upd=",processedData,"&include_raw_data=",rawTraces, sep="") request <- httr::GET(url) if(status_code(request) == 500){ - print("Warning: Failed collect project data.") + cat("Warning: Failed collect project data.\n") return(NULL) } content <- content(request) @@ -29,16 +30,16 @@ getProjectData <- function(email="", token="", projectID="", rawTraces = FALSE){ return(content$data) } else if(content$status == "failed"){ - print(content$notice) + cat(paste(content$notice,"\n", sep="")) return(NULL) } else{ - print("Warning: There was an error receiving the project data") + cat("Warning: There was an error receiving the project data.\n") return(NULL) } } else { - print("Warning: Project does not exist or is not available.") + cat("Warning: Project does not exist or is not available.\n") return(NULL) } } \ No newline at end of file diff --git a/R/getProjectInfo.R b/R/getProjectInfo.R index a3f53be..953ce17 100644 --- a/R/getProjectInfo.R +++ b/R/getProjectInfo.R @@ -19,7 +19,7 @@ getProjectInfo <- function(email="", token="", projectID=""){ url <- paste("https://photosynq.org/api/v3/projects/",toString(projectID),".json?user_email=",email,"&user_token=",token, sep="") request <- httr::GET(url) if(status_code(request) == 500){ - print("Warning: Failed to get project info.") + cat("Warning: Failed to receive the project information.\n") return(NULL) } content <- content(request) @@ -27,16 +27,16 @@ getProjectInfo <- function(email="", token="", projectID=""){ return(content$project) } else if(content$status == "failed"){ - print(content$notice) + cat(paste(content$notice,"\n", sep="")) return(NULL) } else{ - print("Warning: There was an error receiving the project data") + cat("Warning: There was an error receiving the project data\n") return(NULL) } } else { - print("Warning: Project does not exist or is not available.") + cat("Warning: Project does not exist or is not available.\n") return(NULL) } } \ No newline at end of file diff --git a/R/login.R b/R/login.R index 9fd0cae..fe60b39 100644 --- a/R/login.R +++ b/R/login.R @@ -23,28 +23,28 @@ login <- function(email=""){ } pwd <- getPass(msg = "Your PhotosynQ Password: ", forcemask = FALSE) if(is.null(pwd)){ - print("Info: Login canceled.") + cat("Info: Login canceled.\n") return(NULL) } url <- "https://photosynq.org/api/v3/sign_in.json" request <- httr::POST(url, body= list("user[email]" = email,"user[password]" = pwd)) if(status_code(request) == 500){ - print("Warning: Failed to login.") + cat("Warning: Failed to login.\n") return(NULL) } content <- content(request) if(content$status == "success"){ - paste("Hello", content$user$name, sep=" ") + cat("Successfully signed in as: ", content$user$name,"\n", sep=" ") result <- list(email=content$user$email,token=content$user$auth_token,name=content$user$name) return(result) } else if(content$status == "failed"){ - print(content$notice) + cat(paste(content$notice,"\n", sep="")) return(NULL) } } else { - print("Warning: Please provide your email to login.") + cat("Warning: Please provide your email to login.\n") return(NULL) } } \ No newline at end of file diff --git a/R/logout.R b/R/logout.R index 469b4e7..02bed0d 100644 --- a/R/logout.R +++ b/R/logout.R @@ -16,9 +16,9 @@ logout <- function(token=""){ } url <- "https://photosynq.org/api/v3/sign_out.json" request <- httr::DELETE(url, body= list("auth_token" = token)) - print("Goodbye!") + cat("Goodbye!\n") } else { - print("Warning: You have to provide your login token.") + cat("Warning: You have to provide your login token.\n") } } \ No newline at end of file diff --git a/README.md b/README.md index 4cdd8dd..41d4889 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,10 @@ project_info <- PhotosynQ::getProjectInfo(login$email, login$token, ID) ```R ID <- 1556 project_data <- PhotosynQ::getProjectData(login$email, login$token, ID) + +# Use raw data +processed_data <- FALSE +project_data <- PhotosynQ::getProjectData(login$email, login$token, ID, processed_data) ``` #### Create a Data frame