Skip to content

Commit

Permalink
some string optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Dec 14, 2023
1 parent a265f5b commit b9bab35
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ importFrom(ggplot2,theme_grey)
importFrom(mirai,mirai)
importFrom(nanonext,ncurl)
importFrom(nanonext,sha256)
importFrom(nanonext,strcat)
importFrom(shiny,HTML)
importFrom(shiny,checkboxInput)
importFrom(shiny,column)
Expand Down
2 changes: 1 addition & 1 deletion R/archive.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ writeArchive <- function(object, file) {
stop("in archive(object, file): 'file' must be supplied as a string.\nDid you omit the surrounding quotes \"\"?", call. = FALSE)

if (file.exists(file) && interactive()) {
continue <- readline(prompt = paste0("The file '", file, "' already exists. Overwrite? [y/N] "))
continue <- readline(prompt = sprintf("The file '%s' already exists. Overwrite? [y/N] ", file))
continue %in% c("y", "Y", "yes", "YES") || {
message("Request cancelled")
return(invisible())
Expand Down
2 changes: 1 addition & 1 deletion R/ichimoku-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
#' scale_x_continuous scale_y_continuous Stat StatIdentity theme theme_grey
#' %+replace%
#' @importFrom mirai mirai
#' @importFrom nanonext ncurl sha256
#' @importFrom nanonext ncurl sha256 strcat
#' @importFrom shiny checkboxInput column downloadButton downloadHandler HTML
#' fillPage fluidPage fluidRow hoverOpts invalidateLater isolate
#' numericInput observeEvent plotOutput reactive reactiveVal renderPlot
Expand Down
7 changes: 3 additions & 4 deletions R/iplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,10 @@ drawInfotip <- function(sidx, sdata, left, top, type, custom = NULL) {
"<br />Chikou: ", signif(sdata[["chikou"]], digits = 5),
switch(
type,
r = paste0("<br />R-indicator: ", signif(100 * sdata[["osc_typ_slw"]], digits = 3)),
s = paste0("<br />S-fast: ", signif(100 * sdata[["osc_typ_fst"]], digits = 3),
"<br />S-slow: ", signif(100 * sdata[["osc_typ_slw"]], digits = 3)),
r = sprintf("<br />R-indicator: %.3g", 100 * sdata[["osc_typ_slw"]]),
s = sprintf("<br />S-fast: %.3g<br />S-slow: %.3g", 100 * sdata[["osc_typ_fst"]], 100 * sdata[["osc_typ_slw"]]),
line = ,
bar = paste0("<br />", custom, " : ", signif(sdata[[custom]], digits = 5)),
bar = sprintf("<br />%s: %.5g", custom, sdata[[custom]]),
NULL
),
"</div>"))
Expand Down
14 changes: 7 additions & 7 deletions R/oanda.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ getPrices <- function(instrument, granularity, count = NULL, from = NULL,
url <- paste0("https://api-fx", switch(server, practice = "practice", live = "trade"),
".oanda.com/v3/instruments/", instrument, "/candles?granularity=",
granularity, "&price=", price,
if (!is.null(count)) paste0("&count=", count),
if (!is.null(from)) paste0("&from=", from),
if (!is.null(to)) paste0("&to=", to))
if (length(count)) strcat("&count=", as.character(count)),
if (length(from)) strcat("&from=", as.character(from)),
if (length(to)) strcat("&to=", as.character(to)))
resp <- ncurl(url,
convert = FALSE,
follow = TRUE,
headers = c(Authorization = paste0("Bearer ", apikey),
headers = c(Authorization = strcat("Bearer ", apikey),
`Accept-Datetime-Format` = "UNIX",
`User-Agent` = .user_agent),
response = "date")
Expand Down Expand Up @@ -325,7 +325,7 @@ oanda_stream <- function(instrument, display = 8L, limit, server, apikey) {
url <- paste0("https://stream-fx", switch(server, practice = "practice", live = "trade"),
".oanda.com/v3/accounts/", do_$getAccount(server = server, apikey = apikey),
"/pricing/stream?instruments=", instrument)
headers <- c(Authorization = paste0("Bearer ", apikey),
headers <- c(Authorization = strcat("Bearer ", apikey),
`Accept-Datetime-Format` = "UNIX",
`User-Agent` = .user_agent)

Expand Down Expand Up @@ -1011,7 +1011,7 @@ oanda_positions <- function(instrument, time, server, apikey) {
".oanda.com/v3/instruments/", instrument, "/positionBook",
if (!missing(time)) paste0("?time=", unclass(as.POSIXct(time))))
resp <- ncurl(url, convert = FALSE, follow = TRUE,
headers = c(Authorization = paste0("Bearer ", apikey),
headers = c(Authorization = strcat("Bearer ", apikey),
`Accept-Datetime-Format` = "UNIX", `User-Agent` = .user_agent))
resp[["status"]] == 200L ||
stop("status code ", resp[["status"]], " - ",
Expand Down Expand Up @@ -1103,7 +1103,7 @@ oanda_orders <- function(instrument, time, server, apikey) {
".oanda.com/v3/instruments/", instrument, "/orderBook",
if (!missing(time)) paste0("?time=", unclass(as.POSIXct(time))))
resp <- ncurl(url, convert = FALSE, follow = TRUE,
headers = c(Authorization = paste0("Bearer ", apikey),
headers = c(Authorization = strcat("Bearer ", apikey),
`Accept-Datetime-Format` = "UNIX", `User-Agent` = .user_agent))
resp[["status"]] == 200L ||
stop("status code ", resp[["status"]], " - ",
Expand Down
2 changes: 1 addition & 1 deletion R/strat.R
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ stratcombine <- function(s1, s2) {
strat2 <- attr(s2, "strat")["Strategy", ][[1L]]
identical(strat1, strat2) && return(s1)

strategy <- paste0(strat1, " & ", strat2)
strategy <- sprintf("%s & %s", strat1, strat2)
p2 <- attr(s1, "periods")[2L]
xlen <- dim(core1)[1L]
end <- xlen - p2
Expand Down
4 changes: 2 additions & 2 deletions R/switch.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ do_ <- function() {
practice = "https://api-fxpractice.oanda.com/v3/accounts",
live = "https://api-fxtrade.oanda.com/v3/accounts")
resp <- ncurl(url, convert = FALSE, follow = TRUE,
headers = c("Authorization" = paste0("Bearer ", apikey),
headers = c("Authorization" = strcat("Bearer ", apikey),
"User-Agent" = .user_agent))
resp[["status"]] == 200L ||
stop("status code ", resp[["status"]], " - ", deserialize_json(resp[["data"]]), call. = FALSE)
Expand All @@ -139,7 +139,7 @@ do_ <- function() {
".oanda.com/v3/accounts/", do_$getAccount(server = server, apikey = apikey),
"/instruments")
resp <- ncurl(url, convert = FALSE, follow = TRUE,
headers = c("Authorization" = paste0("Bearer ", apikey),
headers = c("Authorization" = strcat("Bearer ", apikey),
"User-Agent" = .user_agent))
resp[["status"]] == 200L ||
stop("status code ", resp[["status"]], " - ", deserialize_json(resp[["data"]]), call. = FALSE)
Expand Down

0 comments on commit b9bab35

Please sign in to comment.