How can I use the sink and still receive messages printed in R?

I am trying to save a boost log using the sink function, as the following code:

 require(xgboost) require(R.utils) data(iris) train.model <- model.matrix(Sepal.Length~., iris) dtrain <- xgb.DMatrix(data=train.model, label=iris$Sepal.Length) xgb_grid = list(eta = 0.05, max_depth = 5, subsample = 0.7, gamma = 0.3, min_child_weight = 1) sink("evaluationLog.txt") fit_boost <-xgb.cv(data = dtrain, nrounds = 1000, objective = "reg:linear", eval_metric = "logloss", params = xgb_grid, colsample_bytree = 0.7, early_stopping_rounds = 100, nfold = 5, prediction = TRUE, maximize = FALSE ) sink() 

However, I don’t see what’s happening, because it does not print the output of the function and / or message.

My question is, how can I extract a .txt file from sink and see what prints? (in this case will be xgb.cv )?

Thanks!

+5
source share
1 answer

Use split argument:

 sink('test.txt', split = TRUE) print(letters) # [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" #[18] "r" "s" "t" "u" "v" "w" "x" "y" "z" sink() 

As you can see above, it will print to the console, and you will also find the test.txt file in your current directory.

+6
source

Source: https://habr.com/ru/post/1274068/


All Articles