Skip to content
Snippets Groups Projects
Commit 2c4c49f6 authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle
Browse files

improve file_path and id

parent ffb3c390
No related branches found
No related tags found
No related merge requests found
Package: algoli
Type: Package
Version: 0.0.2
Version: 0.0.3
Authors@R: c(person("Jean-Marie", "Lepioufle", , "jml@nilu.no", role=c("aut","cre")),
person("NILU",role="cph"))
Title: algoli
......@@ -9,6 +9,8 @@ Description: Make the use of algorithms for fitting/prediction easy.
One simple syntax for every libraries.
Depends:
R (>= 3.4.1)
Imports:
stringi
Suggests:
knitr
License: MIT + file LICENSE
......
......@@ -10,19 +10,20 @@
#' @param predictors predictors in character
#' @param train train percentage
#' @param test test percentage
#' @param MODEL_DIR boolean save model in a specific recoverable folder, temporary solution
#' @keywords algoli
#' @export
#' @examples
#' \dontrun{
#' do_fit()
#' }
do_fit <- function(service,algorithm=NULL,...,dataset,col_bind=NULL,target,predictors, train=0.8,test=0.2,MODEL_DIR=FALSE){
do_fit <- function(service,algorithm=NULL,...,dataset,col_bind=NULL,target,predictors, train=0.8,test=0.2){
fileCheck_path <- file.path(getwd(),"algoli")
id <- stringi::stri_rand_strings(1, 16,'[a-z0-9]')
fileCheck_path <- normalizePath(file.path(tempdir(),"algoli"),mustWork = FALSE)
fileCheck_path <- normalizePath(fileCheck_path,mustWork = FALSE)
dir.create(fileCheck_path, showWarnings = TRUE, recursive = TRUE)
fileCheck <- file.path(fileCheck_path,"fit-check.log")
fileCheck <- file.path(fileCheck_path,paste0('fit-check_',id,'_.log'))
file.create(fileCheck)
target <- gsub("\\.","_",target)
......@@ -45,21 +46,9 @@ do_fit <- function(service,algorithm=NULL,...,dataset,col_bind=NULL,target,predi
# exporting model ...
cat(c(as.character(Sys.time()),"export model\n"), file=fileCheck,append=TRUE)
tmp_model_path <- normalizePath(file.path(tempdir(),"model"),mustWork = FALSE)
tmp_model_path <- normalizePath(file.path(tempdir(),"algoli",id),mustWork = FALSE)
dir.create(tmp_model_path, showWarnings = TRUE, recursive = TRUE)
from <- hello$export_model(res_fit,tmp_model_path)
if (!MODEL_DIR) {
tmp <- list(id=NULL,model_path=from)
} else if (MODEL_DIR) {
# for an internal access to the binary, temporary solution
tmp <- dir_tmp_model()
if (!is.null(tmp$model_path)){
to <- file.path(tmp$model_path,"model.mod")
file.copy(from=from,to=to)
} else tmp <- list(id=NULL,model_path=NULL)
} else tmp <- list(id=NULL,model_path=NULL)
model_path <- hello$export_model(res_fit,tmp_model_path)
# Prediction on the test dataset ...
cat(c(as.character(Sys.time()),"predict\n"), file=fileCheck,append=TRUE)
......@@ -70,9 +59,10 @@ do_fit <- function(service,algorithm=NULL,...,dataset,col_bind=NULL,target,predi
args = list(...),
target = target,
predictors = predictors,
col_bind = col_bind,
pred = res_pred,
id = tmp$id,
path = tmp$model_path)
id = id,
path = model_path)
# disconnect ...
cat(c(as.character(Sys.time()),"disconnect\n"), file=fileCheck,append=TRUE)
......
......@@ -14,10 +14,12 @@
#' }
do_predict <- function(service,model_path=NULL,model_id=NULL,dataset=NULL,col_bind=NULL){
fileCheck_path <- file.path(getwd(),"algoli")
id <- stringi::stri_rand_strings(1, 16,'[a-z0-9]')
fileCheck_path <- normalizePath(file.path(tempdir(),"algoli"),mustWork = FALSE)
fileCheck_path <- normalizePath(fileCheck_path,mustWork = FALSE)
dir.create(fileCheck_path, showWarnings = TRUE, recursive = TRUE)
fileCheck <- file.path(fileCheck_path,"predict-check.log")
fileCheck <- file.path(fileCheck_path,paste0('predict-check_',id,'_.log'))
file.create(fileCheck)
# new algoli
......
......@@ -6,7 +6,7 @@
do_fit}
\usage{
do_fit(service, algorithm = NULL, ..., dataset, col_bind = NULL,
target, predictors, train = 0.8, test = 0.2, MODEL_DIR = FALSE)
target, predictors, train = 0.8, test = 0.2)
}
\arguments{
\item{service}{service}
......@@ -26,8 +26,6 @@ do_fit(service, algorithm = NULL, ..., dataset, col_bind = NULL,
\item{train}{train percentage}
\item{test}{test percentage}
\item{MODEL_DIR}{boolean save model in a specific recoverable folder, temporary solution}
}
\description{
do_fit
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment