lgb.unloader.Rd 1.77 KB
Newer Older
Guolin Ke's avatar
Guolin Ke committed
1
2
3
4
5
6
7
8
9
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lgb.unloader.R
\name{lgb.unloader}
\alias{lgb.unloader}
\title{LightGBM unloading error fix}
\usage{
lgb.unloader(restore = TRUE, wipe = FALSE, envir = .GlobalEnv)
}
\arguments{
10
11
12
\item{restore}{Whether to reload \code{LightGBM} immediately after detaching from R.
Defaults to \code{TRUE} which means automatically reload \code{LightGBM} once
unloading is performed.}
James Lamb's avatar
James Lamb committed
13

14
15
\item{wipe}{Whether to wipe all \code{lgb.Dataset} and \code{lgb.Booster} from the global
environment. Defaults to \code{FALSE} which means to not remove them.}
Guolin Ke's avatar
Guolin Ke committed
16

17
18
\item{envir}{The environment to perform wiping on if \code{wipe == TRUE}. Defaults to
\code{.GlobalEnv} which is the global environment.}
Guolin Ke's avatar
Guolin Ke committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
}
\value{
NULL invisibly.
}
\description{
Attempts to unload LightGBM packages so you can remove objects cleanly without having to restart R. This is useful for instance if an object becomes stuck for no apparent reason and you do not want to restart R to fix the lost object.
}
\examples{
library(lightgbm)
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)
data(agaricus.test, package = "lightgbm")
test <- agaricus.test
dtest <- lgb.Dataset.create.valid(dtrain, test$data, label = test$label)
params <- list(objective = "regression", metric = "l2")
valids <- list(test = dtest)
36
37
38
39
40
41
42
43
44
model <- lgb.train(
  params = params
  , data = dtrain
  , nrounds = 10
  , valids = valids
  , min_data = 1
  , learning_rate = 1
  , early_stopping_rounds = 5
)
Nikita Titov's avatar
Nikita Titov committed
45
46

\dontrun{
Guolin Ke's avatar
Guolin Ke committed
47
48
49
50
51
52
lgb.unloader(restore = FALSE, wipe = FALSE, envir = .GlobalEnv)
rm(model, dtrain, dtest) # Not needed if wipe = TRUE
gc() # Not needed if wipe = TRUE

library(lightgbm)
# Do whatever you want again with LightGBM without object clashing
Nikita Titov's avatar
Nikita Titov committed
53
}
Guolin Ke's avatar
Guolin Ke committed
54
55

}