Skip to content

Commit

Permalink
Console message using message() instead of cat
Browse files Browse the repository at this point in the history
  • Loading branch information
quishqa committed Jan 26, 2022
1 parent 9e4d7f0 commit 0c90cfd
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 54 deletions.
20 changes: 10 additions & 10 deletions R/CetesbRetrieve.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ CetesbRetrieve <- function(username, password,

# Adding query summary
if (verbose){
cat("Your query is:\n") # nocov
cat("Parameter:", pol_name, "\n") # nocov
cat("Air quality staion:", aqs_name, "\n") # nocov
cat("Period: From", start_date, "to", end_date, "\n") # nocov
message("Your query is:") # nocov
message("Parameter: ", pol_name) # nocov
message("Air quality staion: ", aqs_name) # nocov
message("Period: From ", start_date," to ", end_date) # nocov
}


Expand Down Expand Up @@ -115,7 +115,7 @@ CetesbRetrieve <- function(username, password,
if (ncol(dat) != 19){
dat <- data.frame(date = all.dates$date , pol = NA, aqs = aqs_name, # nocov
stringsAsFactors = FALSE) # nocov
cat(paste0('No data available for ', pol_name), "\n") # nocov
message(paste0('No data available for ', pol_name)) # nocov
} else if (ncol(dat) == 19) {
names(dat) <- cet.names
dat$date <- paste(dat$day, dat$hour, sep = '_')
Expand All @@ -126,15 +126,15 @@ CetesbRetrieve <- function(username, password,
dat <- merge(all.dates, dat, all = TRUE)

if (nrow(dat) != nrow(all.dates)){
cat(paste0('Dates missmatch ', # nocov start
unique(stats::na.omit(dat$est))), "\n")
cat('Duplicated date in ',
dat$date[duplicated(dat$date)], "\n")
message(paste0('Dates missmatch ', # nocov start
unique(stats::na.omit(dat$est))))
message('Duplicated date in ',
dat$date[duplicated(dat$date)])
dat <- data.frame(date = dat$date , pol = dat$value,
aqs = aqs_name,
stringsAsFactors = FALSE)
} else {
cat(paste0('Download OK ', pol_abr), "\n")
message(paste0('Download OK ', pol_abr))
dat <- data.frame(date = all.dates$date , pol = dat$value ,
aqs = aqs_name, stringsAsFactors = FALSE)
} # nocov end
Expand Down
12 changes: 6 additions & 6 deletions R/CetesbRetrieveMet.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ CetesbRetrieveMet <- function(username, password,

# Adding query summary
if (verbose){
cat("Your query is:\n")
cat("Parameter: TC, RH, WS, WD, Pressure \n")
cat("Air quality station:", aqs_name, "\n")
cat("Period: From", start_date, "to", end_date, "\n")
message("Your query is:")
message("Parameter: TC, RH, WS, WD, Pressure")
message("Air quality station: ", aqs_name)
message("Period: From ", start_date, " to ", end_date)
}

tc <- CetesbRetrieve(username, password, 25,
Expand Down Expand Up @@ -77,8 +77,8 @@ CetesbRetrieveMet <- function(username, password,
p = p$pol,
aqs = tc$aqs,
stringsAsFactors = FALSE)
cat(paste(
"Download complete for", unique(all_met$aqs), "\n"
message(paste(
"Download complete for", unique(all_met$aqs)
))

if (to_csv){
Expand Down
14 changes: 7 additions & 7 deletions R/CetesbRetrieveMetPol.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ CetesbRetrieveMetPol <- function(username, password,

# Adding query summary
if (verbose){
cat("Your query is:\n")
cat("Parameter: TC, RH, WS, WD, Pressure,\n",
"O3, NO, NO2, NOX, PM2.5, PM10, CO \n")
cat("Air quality station:", aqs_name, "\n")
cat("Period: From", start_date, "to", end_date, "\n")
message("Your query is: ")
message(paste("Parameter: TC, RH, WS, WD, Pressure,",
"O3, NO, NO2, NOX, PM2.5, PM10, CO"))
message("Air quality station: ", aqs_name)
message("Period: From", start_date, " to ", end_date)
}

tc <- CetesbRetrieve(username, password, 25,
Expand Down Expand Up @@ -116,8 +116,8 @@ CetesbRetrieveMetPol <- function(username, password,
pm25 = pm25$pol,
aqs = o3$aqs,
stringsAsFactors = FALSE)
cat(paste(
"Download complete for", unique(all_data$aqs), "\n"
message(paste(
"Download complete for", unique(all_data$aqs)
))

if (to_csv){
Expand Down
8 changes: 4 additions & 4 deletions R/CetesbRetrieveParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ CetesbRetrieveParam <- function(username, password, parameters,

# Adding query summary
if (verbose){
cat("Your query is:\n")
cat("Parameter:", paste(codes_df$name, collapse = ", "), "\n")
cat("Air quality station:", aqs_name, "\n")
cat("Period: From", start_date, "to", end_date, "\n")
message("Your query is:")
message("Parameter: ", paste(codes_df$name, collapse = ", "))
message("Air quality station: ", aqs_name)
message("Period: From ", start_date, " to ", end_date)
}

# Downloading data
Expand Down
12 changes: 6 additions & 6 deletions R/CetesbRetrievePol.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ CetesbRetrievePol <- function(username, password,

# Adding query summary
if (verbose){
cat("Your query is:\n")
cat("Parameter: O3, NO, NO2, NOX, MP2.5, MP10, CO\n")
cat("Air quality station:", aqs_name, "\n")
cat("Period: From", start_date, "to", end_date, "\n")
message("Your query is:")
message("Parameter: O3, NO, NO2, NOX, MP2.5, MP10, CO")
message("Air quality station: ", aqs_name)
message("Period: From ", start_date, " to ", end_date)
}

o3 <- CetesbRetrieve(username, password, 63,
Expand Down Expand Up @@ -88,8 +88,8 @@ CetesbRetrievePol <- function(username, password,
pm25 = pm25$pol,
aqs = o3$aqs,
stringsAsFactors = FALSE)
cat(paste(
"Download complete for", unique(all_pol$aqs), "\n"
message(paste(
"Download complete for", unique(all_pol$aqs)
))

if (to_csv){
Expand Down
8 changes: 4 additions & 4 deletions R/MonitorArRetrieveMet.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ MonitorArRetrieveMet <- function(start_date, end_date, aqs_code,
aqs_name <- aqs_monitor_ar$name[aqs_monitor_ar$code == aqs_code]

if (verbose){
cat("Your query is:\n")
cat("Parameter:", paste(params, collapse = ", "), "\n")
cat("Air quality station:", aqs_name, "\n")
cat("Period: From", start_date, "to", end_date, "\n")
message("Your query is:")
message("Parameter: ", paste(params, collapse = ", "))
message("Air quality station: ", aqs_name)
message("Period: From ", start_date, " to ", end_date)
}

all_met <- MonitorArRetrieveParam(start_date, end_date, aqs_code,
Expand Down
8 changes: 4 additions & 4 deletions R/MonitorArRetrieveMetPol.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ MonitorArRetrieveMetPol <- function(start_date, end_date, aqs_code,
aqs_name <- aqs_monitor_ar$name[aqs_monitor_ar$code == aqs_code]

if (verbose){
cat("Your query is:\n")
cat("Parameter:", paste(params, collapse = ", "), "\n")
cat("Air quality station:", aqs_name, "\n")
cat("Period: From", start_date, "to", end_date, "\n")
message("Your query is: ")
message("Parameter: ", paste(params, collapse = ", "))
message("Air quality station: ", aqs_name)
message("Period: From ", start_date, " to ", end_date)
}

all_data <- MonitorArRetrieveParam(start_date, end_date, aqs_code,
Expand Down
16 changes: 8 additions & 8 deletions R/MonitorArRetrieveParam.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ MonitorArRetrieveParam <- function(start_date, end_date, aqs_code, parameters,

# Adding query summary
if (verbose){
cat("Your query is:\n")
cat("Parameter:", paste(parameters, collapse = ", "), "\n")
cat("Air quality station:", aqs_name, "\n")
cat("Period: From", start_date, "to", end_date, "\n")
message("Your query is:")
message("Parameter: ", paste(parameters, collapse = ", "))
message("Air quality station: ", aqs_name)
message("Period: From ", start_date, " to ", end_date)
}

start_date_format <- as.POSIXct(strptime(start_date, format="%d/%m/%Y"),
Expand Down Expand Up @@ -88,8 +88,8 @@ MonitorArRetrieveParam <- function(start_date, end_date, aqs_code, parameters,
))
# Checking request
if (res$status_code == 200){
cat("Succesful request \n")
cat(paste("Downloading ", paste(parameters, collapse = " ")), "\n")
message("Succesful request")
message(paste("Downloading ", paste(parameters, collapse = " ")))
} else {
stop("Unsuccesful request. Something goes wrong", call. = FALSE) # nocov
}
Expand All @@ -99,7 +99,7 @@ MonitorArRetrieveParam <- function(start_date, end_date, aqs_code, parameters,

# Create an empty data frame is there is no input
if (length(raw_data$feature) == 0){
cat("Data unavailable", "\n") # nocov start
message("Data unavailable") # nocov start
data_aqs <- data.frame(Data = NA)
for (p in parameters){
data_aqs[[p]] <- NA # nocov end
Expand All @@ -126,7 +126,7 @@ MonitorArRetrieveParam <- function(start_date, end_date, aqs_code, parameters,
)

if (nrow(all_dates) != nrow(data_aqs)){
cat("Padding out missing dates with NA \n") # nocov
message("Padding out missing dates with NA") # nocov
data_aqs <- merge(all_dates, data_aqs, all = TRUE) # nocov
}

Expand Down
8 changes: 4 additions & 4 deletions R/MonitorArRetrievePol.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ MonitorArRetrievePol <- function(start_date, end_date, aqs_code,
aqs_name <- aqs_monitor_ar$name[aqs_monitor_ar$code == aqs_code]

if (verbose){
cat("Your query is:\n")
cat("Parameter:", paste(params, collapse = ", "), "\n")
cat("Air quality station:", aqs_name, "\n")
cat("Period: From", start_date, "to", end_date, "\n")
message("Your query is:")
message("Parameter: ", paste(params, collapse = ", "))
message("Air quality station: ", aqs_name)
message("Period: From ", start_date, " to ", end_date)
}

all_pol <- MonitorArRetrieveParam(start_date, end_date, aqs_code,
Expand Down
2 changes: 1 addition & 1 deletion R/WriteCSV.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ WriteCSV <- function(aqs_data_df, aqs_name, start_date, end_date, vars){
utils::write.table(aqs_data_df, file_name, sep = ",", row.names = FALSE)

file_path <- paste(getwd(), file_name, sep = "/")
cat(paste(file_path, "was created \n"))
message(paste(file_path, "was created"))
}

0 comments on commit 0c90cfd

Please sign in to comment.