Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
a2b60e84
Unverified
Commit
a2b60e84
authored
Oct 22, 2021
by
david-cortes
Committed by
GitHub
Oct 21, 2021
Browse files
[R-package] expand user paths in file names (#4687)
parent
d88b4456
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
3 deletions
+11
-3
R-package/R/lgb.Booster.R
R-package/R/lgb.Booster.R
+6
-0
R-package/R/lgb.Dataset.R
R-package/R/lgb.Dataset.R
+2
-2
R-package/R/lgb.Predictor.R
R-package/R/lgb.Predictor.R
+3
-1
No files found.
R-package/R/lgb.Booster.R
View file @
a2b60e84
...
...
@@ -76,6 +76,8 @@ Booster <- R6::R6Class(
stop
(
"lgb.Booster: Can only use a string as model file path"
)
}
modelfile
<-
path.expand
(
modelfile
)
# Create booster from model
handle
<-
.Call
(
LGBM_BoosterCreateFromModelfile_R
...
...
@@ -425,6 +427,8 @@ Booster <- R6::R6Class(
num_iteration
<-
self
$
best_iter
}
filename
<-
path.expand
(
filename
)
.Call
(
LGBM_BoosterSaveModel_R
,
private
$
handle
...
...
@@ -857,6 +861,7 @@ lgb.load <- function(filename = NULL, model_str = NULL) {
if
(
!
is.character
(
filename
))
{
stop
(
"lgb.load: filename should be character"
)
}
filename
<-
path.expand
(
filename
)
if
(
!
file.exists
(
filename
))
{
stop
(
sprintf
(
"lgb.load: file '%s' passed to filename does not exist"
,
filename
))
}
...
...
@@ -917,6 +922,7 @@ lgb.save <- function(booster, filename, num_iteration = NULL) {
if
(
!
(
is.character
(
filename
)
&&
length
(
filename
)
==
1L
))
{
stop
(
"lgb.save: filename should be a string"
)
}
filename
<-
path.expand
(
filename
)
# Store booster
return
(
...
...
R-package/R/lgb.Dataset.R
View file @
a2b60e84
...
...
@@ -243,7 +243,7 @@ Dataset <- R6::R6Class(
handle
<-
.Call
(
LGBM_DatasetCreateFromFile_R
,
private
$
raw_data
,
path.expand
(
private
$
raw_data
)
,
params_str
,
ref_handle
)
...
...
@@ -742,7 +742,7 @@ Dataset <- R6::R6Class(
.Call
(
LGBM_DatasetSaveBinary_R
,
private
$
handle
,
fname
,
path.expand
(
fname
)
)
return
(
invisible
(
self
))
}
...
...
R-package/R/lgb.Predictor.R
View file @
a2b60e84
...
...
@@ -35,7 +35,7 @@ Predictor <- R6::R6Class(
# Create handle on it
handle
<-
.Call
(
LGBM_BoosterCreateFromModelfile_R
,
modelfile
,
path.expand
(
modelfile
)
)
private
$
need_free_handle
<-
TRUE
...
...
@@ -96,6 +96,8 @@ Predictor <- R6::R6Class(
# Check if data is a file name and not a matrix
if
(
identical
(
class
(
data
),
"character"
)
&&
length
(
data
)
==
1L
)
{
data
<-
path.expand
(
data
)
# Data is a filename, create a temporary file with a "lightgbm_" pattern in it
tmp_filename
<-
tempfile
(
pattern
=
"lightgbm_"
)
on.exit
(
unlink
(
tmp_filename
),
add
=
TRUE
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment