You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
summary.corpus implementation not suppressing output when assigned to a variable #926
Elsewhere in R when i assign summary(some object) to a variable as shown below with mtcars data object it suppresses any output the summary() call would have normally produced. I'm finding that summary(quanteda::corpus object) isn't doing that and not sure if its by design or not.
Where it was an issue for me is in R markdown, *.Rmd, work where i wanted to assign summary(quanteda:corpus object) to a variable so i could then output just pieces of summary of interest vs the more verbose output. Tried using invisible() wrapper with no change in results.
Here is a simple repro of what i'm seeing . . .
> data(mtcars); class(mtcars)
[1] "data.frame"
> mtcarsSummary <- summary(mtcars)
> corpusObject <- quanteda::corpus("some corpus text of no consequence"); class(corpusObject)
[1] "corpus" "list"
> invisible(corpusSummary <- summary(corpusObject))
Corpus consisting of 1 document.
Text Types Tokens Sentences
text1 6 6 1
Source: D:/src/repos/dsJhuC10/* on x86-64 by ob1
Created: Sat Aug 12 11:43:57 2017
Notes:
Warning message:
In nsentence.character(object, ...) :
<snip />
Hello Ken. Adding to myusrn's point, I wrote a test R Markdown report to see whether I could completely suppress quanteda messages in library() and other knitr code chunks. The results are posted on rpubs at Suppressing quanteda Output. summary() suppresses the output if verbose=FALSE is directly listed as an argument to summary(), but not with the quanteda_options() function.
That's actually intentional at the moment, since we wanted the default for summary.corpus() to produce printed output, not to return a data.frame and invoke the data.frame print method (if not captured). For, most of the functions, users will want the
quanteda_options("verbose")
# [1] FALSE
except for summary.corpus().
However this is slightly inconsistent with the method for summary.data.frame(), which returns a table, whereas summary.corpus() returns a data.frame.
So, the immediate solution to not printing the output here is simply to specify
Can summary.corpus() implementation easily determine when its being called in the context of a variable assignment and when it is not?
If so then given what i see with other summary implementations, summary.numeric/character/data.table(), is that they output data when no variable assignment is happening and suppress it when a variable assignment is happening.
That would be my preferred default user experience with summary.corpus(), optionally overrided with verbose = TRUE param, if its doable without having to introduce significant complexity.
Thanks for the follow up, Ken. Generally speaking, I like the verbose output. However, if I am including quanteda functions in an R Markdown report, I'd like to:
Suppress all warnings / messages with a global quanteda parameter (i.e. have quanteda_options() work consistently across all quanteda functions), and
Use library() options to prevent quanteda startup messages from being written to the output.
@len, don't the knitr::opts_chunk$set(..., message = FALSE, warning = FALSE) settings address your concerns over messages and warnings in r markdown output with quanteda library load and function calls like it does for other libraries?
The library() function arguments should suppress messages from quanteda, but it still writes its load message (including X of Y cores for parallel processing) to the output file.
Thanks @lgreski and @myusrn these are good points and should be straightforward to fix. I'll get to them in a few days.
On summary.corpus() I think the simplest solution is to remove the verbose argument altogether, and make it return an additionally classed data.frame that has a slightly modified print method.
I’ve experimented now and done some research, and it turns out that the quanteda startup message behaviour is entirely consistent with other packages, e.g.:
library("data.table", quietly=TRUE, warn.conflicts=FALSE, verbose=FALSE)
## data.table 1.10.4## The fastest way to learn (by data.table authors): https://www.datacamp.com/courses/data-analysis-the-data-table-way## Documentation: ?data.table, example(data.table) and browseVignettes("data.table")## Release notes, videos and slides: http://r-datatable.com
The library() arguments are very strangely designed, but hey that’s not our doing.
If you attach the package normally, you will see the message, plus the namespace conflict warning about View, and the startup messages:
library(“quanteda")## quanteda version 0.99## Using 4 of 8 threads for parallel computing#### Attaching package: ‘quanteda’#### The following object is masked from ‘package:utils’:#### View
If you do not want the namespace conflict warnings, use this:
detach("package:quanteda")
library(“quanteda", warn.conflicts = FALSE)## quanteda version 0.99## Using 4 of 8 threads for parallel computing
If you do not want any output at all, use this (in your RMarkdown file for instance:
Activity
lgreski commentedon Aug 12, 2017
Hello Ken. Adding to myusrn's point, I wrote a test R Markdown report to see whether I could completely suppress quanteda messages in library() and other knitr code chunks. The results are posted on rpubs at Suppressing quanteda Output. summary() suppresses the output if verbose=FALSE is directly listed as an argument to summary(), but not with the quanteda_options() function.
regards,
Len Greski
kbenoit commentedon Aug 13, 2017
That's actually intentional at the moment, since we wanted the default for
summary.corpus()to produce printed output, not to return a data.frame and invoke the data.frame print method (if not captured). For, most of the functions, users will want theexcept for
summary.corpus().However this is slightly inconsistent with the method for
summary.data.frame(), which returns a table, whereassummary.corpus()returns a data.frame.So, the immediate solution to not printing the output here is simply to specify
Advice on how you'd prefer to see this function work is welcome!
myusrn commentedon Aug 13, 2017
Can summary.corpus() implementation easily determine when its being called in the context of a variable assignment and when it is not?
If so then given what i see with other summary implementations, summary.numeric/character/data.table(), is that they output data when no variable assignment is happening and suppress it when a variable assignment is happening.
That would be my preferred default user experience with summary.corpus(), optionally overrided with verbose = TRUE param, if its doable without having to introduce significant complexity.
lgreski commentedon Aug 13, 2017
Thanks for the follow up, Ken. Generally speaking, I like the verbose output. However, if I am including quanteda functions in an R Markdown report, I'd like to:
regards,
Len
myusrn commentedon Aug 13, 2017
@len, don't the
knitr::opts_chunk$set(..., message = FALSE, warning = FALSE)settings address your concerns over messages and warnings in r markdown output with quanteda library load and function calls like it does for other libraries?lgreski commentedon Aug 15, 2017
@myusrn Apparently quanteda does not obey all of these settings, as I demonstrated in my Rpubs test. The code block where I load quanteda includes:
The
library()function arguments should suppress messages from quanteda, but it still writes its load message (including X of Y cores for parallel processing) to the output file.regards,
Len
kbenoit commentedon Aug 15, 2017
Thanks @lgreski and @myusrn these are good points and should be straightforward to fix. I'll get to them in a few days.
On
summary.corpus()I think the simplest solution is to remove theverboseargument altogether, and make it return an additionally classed data.frame that has a slightly modified print method.kbenoit commentedon Sep 7, 2017
I’ve experimented now and done some research, and it turns out that the quanteda startup message behaviour is entirely consistent with other packages, e.g.:
The
library()arguments are very strangely designed, but hey that’s not our doing.If you attach the package normally, you will see the message, plus the namespace conflict warning about
View, and the startup messages:If you do not want the namespace conflict warnings, use this:
If you do not want any output at all, use this (in your RMarkdown file for instance:
lgreski commentedon Sep 8, 2017
Thanks for the explanation, Ken.
Len