Skip to content

Commit

Permalink
switch from stringr to stringi
Browse files Browse the repository at this point in the history
  • Loading branch information
mllg committed Apr 13, 2015
1 parent d796e7f commit 61e9be7
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Imports:
data.table,
digest,
RCurl,
stringr,
stringi,
XML,
RWeka,
mlr,
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ import(checkmate)
import(data.table)
import(digest)
import(mlr)
import(stringr)
import(stringi)
importFrom(stats,setNames)
18 changes: 9 additions & 9 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#' @title OpenML configuration.
#'
#' @description
#' After loading the package, it tries to find a configuration in your home
#' After loading the package, it tries to find a configuration in your home
#' directory. The R command \code{path.expand("~/.openml/config")} gives you the
#' full path to the configuration file on your operating system.
#'
#'
#' For further information please read the configuration section in
#' \url{https://github.com/openml/r/wiki}.
#'
Expand All @@ -22,9 +22,9 @@ readConfigFile = function(conffile) {
conf = new.env(parent = emptyenv())
# FIXME: we need to check the format of the conf file
# the format is <name> = <value>
lines = Filter(nzchar, str_trim(readLines(conffile)))
lines = str_split(lines, "=")
lines = lapply(lines, str_trim)
lines = Filter(nzchar, stri_trim_both(readLines(conffile)))
lines = stri_split_fixed(lines, "=")
lines = lapply(lines, stri_trim_both)
lines = do.call(rbind, lines)
conf = as.environment(setNames(as.list(lines[, 2L]), lines[, 1L]))
# if (is.error(x))
Expand All @@ -36,7 +36,7 @@ readConfigFile = function(conffile) {
conf$openmldir = path.expand(conf$openmldir)
if (!is.null(conf$cachedir))
conf$cachedir = path.expand(conf$cachedir)

checkConfig(conf)
# FIXME: probably horrible security wise....
if (!is.null(conf$password))
Expand Down Expand Up @@ -148,9 +148,9 @@ getOMLConfig = function() {
return(.OpenML.config)
}

#' Loads a config file from disk to mem
#' Loads a config file from disk to mem
#'
#' @param path [\code{character(1)}]\cr
#' @param path [\code{character(1)}]\cr
#' full path location of the config file to be loaded
#' @return \code{list} of current configuration variables with class \dQuote{OMLConfig}.
#' @family config
Expand All @@ -163,4 +163,4 @@ loadOMLConf = function(path = "~/.openml/config") {
# create cache dir from new config file
createCacheSubDirs(verbosity = FALSE)
invisible(conf)
}
}
8 changes: 4 additions & 4 deletions R/download.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ getServerURL = function(secure = NULL) {
url = getOMLConfig()$server
if (!is.null(secure)) {
pr = ifelse(secure, "https://", "http://")
split = unlist(str_split(url, pattern = "://"))
split = unlist(stri_split_fixed(url, "://"))
if (length(split) == 1L) {
url = paste0(pr, split)
} else if (length(split) == 2L) {
Expand All @@ -24,10 +24,10 @@ getServerURL = function(secure = NULL) {
stop("The server URL in your config file looks strange. Try 'http://www.openml.org'.")
}
}
last.char = str_sub(url, str_length(url), str_length(url))
n = nchar(url)
last.char = stri_sub(url, n, n)
api = ifelse(last.char == "/", "api", "/api")
url = paste0(url, api)
return(url)
paste0(url, api)
}

# download xml from a url / api call to file
Expand Down
2 changes: 1 addition & 1 deletion R/getOMLTask.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ getOMLTask = function(task.id, session.hash = getSessionHash(), verbosity = NULL
data.set.output = NULL
# parse estimation procedure
# trim white space around URL to be a bit more robust
data.splits.url = str_trim(xmlOValS(doc, "/oml:task/oml:input/oml:estimation_procedure/oml:data_splits_url"))
data.splits.url = stri_trim_both(xmlOValS(doc, "/oml:task/oml:input/oml:estimation_procedure/oml:data_splits_url"))
if (is.null(data.splits.url))
data.splits.url = "No URL"

Expand Down
6 changes: 3 additions & 3 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ showMessage = function(verbosity, msg, ..., minlev) {
}

rename = function(x) {
if (is.data.frame(x)) {
setnames(x, str_replace_all(names(x), "_", "."))
if (is.data.table(x)) {
setnames(x, stri_replace_all_fixed(names(x), "_", "."))
} else {
names(x) = str_replace_all(names(x), "_", ".")
names(x) = stri_replace_all_fixed(names(x), "_", ".")
}
x
}
Expand Down
8 changes: 4 additions & 4 deletions R/uploadOMLFlow.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ uploadOMLFlow = function(x, session.hash, verbosity, sourcefile, binaryfile) {
}

#' @export
uploadOMLFlow.OMLFlow = function(x, session.hash = getSessionHash(),
uploadOMLFlow.OMLFlow = function(x, session.hash = getSessionHash(),
verbosity = NULL, sourcefile = NULL, binaryfile = NULL) {
if (is.null(sourcefile) && is.null(binaryfile)) {
stopf("Please provide source and/or binary file.")
Expand Down Expand Up @@ -60,7 +60,7 @@ uploadOMLFlow.OMLFlow = function(x, session.hash = getSessionHash(),
}

#' @export
uploadOMLFlow.Learner = function(x, session.hash = getSessionHash(),
uploadOMLFlow.Learner = function(x, session.hash = getSessionHash(),
verbosity = NULL, sourcefile = NULL, binaryfile = NULL) {
flow = createOMLFlowForMlrLearner(x)

Expand All @@ -87,7 +87,7 @@ checkOMLFlow = function(x, session.hash = getSessionHash(), verbosity = NULL){
url = getAPIURL("openml.implementation.exists", name = x$name, external_version = x$external.version)
content = downloadXML(url, NULL, verbosity, session_hash = session.hash)
doc = parseXMLResponse(content, "Checking existence of flow", "implementation_exists", as.text = TRUE)

return(list(exists = as.logical(xmlRValS(doc, "/oml:implementation_exists/oml:exists")),
doc = doc))
}
Expand Down Expand Up @@ -127,7 +127,7 @@ createOMLFlowForMlrLearner = function(lrn, name = lrn$id, description = NULL, ..
...
)
if (!is.null(lrn$next.learner)) {
identifier = str_split(lrn$next.learner$id, '[.]')[[1L]][2L]
identifier = stri_split_fixed(lrn$next.learner$id, ".")[[1L]][2L]
flow$components = list(createOMLFlowForMlrLearner(lrn$next.learner))
names(flow$components) = identifier
}
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @import checkmate
#' @import digest
#' @import RCurl
#' @import stringr
#' @import stringi
#' @import XML
#' @import RWeka
#' @import mlr
Expand Down

0 comments on commit 61e9be7

Please sign in to comment.