Home > front end >  How can I hide messages in R markdown when "message=FALSE" doesn't work
How can I hide messages in R markdown when "message=FALSE" doesn't work

Time:04-30

I am using R Markdown and text2vec and would like to suppress the messages that come from running the function glove$fit_transform(). I've tried message=FALSE and warning=FALSE, as well as a number hacky attempts to fixing the problem, but to no avail. I would be so, so grateful for your thoughts on this problem.

library(gutenbergr)
library(tidyverse)
library(text2vec)

h_g_wells <- gutenberg_download(35)

h_g_wells <- h_g_wells %>%
  sample_n(20)

vocab_list = list(h_g_wells$text)

it = itoken(vocab_list, progressbar = FALSE)

vocab = create_vocabulary(it)

vocab = prune_vocabulary(vocab, term_count_min = 1)

vectorizer = vocab_vectorizer(vocab)

tcm = create_tcm(it, vectorizer, skip_grams_window = 5)

glove = GlobalVectors$new(rank = 4, x_max = 100)
    
wv_main = glove$fit_transform(tcm, n_iter = 1000, convergence_tol = 0.00000001, n_threads = 24)

Thanks so much for your help.

CodePudding user response:

I don't know this function. Perhaps it triggers a cat. I would try to use this function:

quiet <- function(x) {
  sink(tempfile())
  on.exit(sink())
  invisible(force(x))
}

like this:

quiet(glove$fit_transform(tcm, n_iter = 1000, ......))
  • Related