What is the graphics::par(op) in R? - r

Working with Quanteda in R, and passing DTM to textplot_wordcloud returns the following error
Error in graphics::par(op) :
invalid value specified for graphical parameter "pin"
There's one other question but the answer refers to a specific package that forces the issue and so a workaround is given that is unclear to me. What does this refer to and how can I go about debugging this? I've never come across the "pin" before but I'm presuming this is related to positioning on the graphical plane somehow. Just unsure how to alter settings in quanteda textplot_wordcloud? Any guidance appreciated.

Related

unrecognized function Nn in R

I am learning R package SimInf to simulate data-driven stochastic epidemiological models. As I was reading the documentation I came across an unrecognized funcion Nn when defining a function for epicurves. Specifically, this line:
j <- sample(seq_len(Nn(model)), 1)
Values of model are integers. My guess is that Nn selects non-negative values, however my R does not recognize this function. From documentation it does not look like they pre-defined Nn either. Can someone please tell if they know what "Nn" is for? Thank you.
A way to go is always taking the package-name and triple-":" it, such that you can find nearly all functions inside the package. Maybe you are familiar with namespacing a function via packageName::functionFrompackageTocall. The packageName::: shows (nearly) all functions defined in this package. If you do this in R-Studio with SimInf:: and SimInf:::, you will see that the latter gives much more functions. But you can only find the functions SimInf:::Nd and SimInf:::Nc, not the Nn-function. Hence you will have to go to the github-sources of the package, in this case https://github.com/stewid/SimInf .Then search for Nn the whole repository. You will see that it seems like it is always an int, but this doesn't help you since you want to get ii as a function, not as a variable. Scrolling further down in the search-results, you will find the NEWS.md-file which mentions The 'Nn' function to determine the number of nodes in a model has been replaced with the S4 method 'n_nodes'. in the https://github.com/stewid/SimInf/blob/fd7eb4a29b82a4a97f64b528bb0e78e5474aa8a5/NEWS.md file under SimInf 8.0.0 (2020-09-13). Hence having a current version of SimInf installed, it shouldn't use the method Nn anymore. If you use it in your code, replace it by n_nodes. If you find it in current package code, you can email the package-maintainer that you found a bug in his code.
TLDR: Nn is an outdated version of n_nodes

Is there a way to define a current quarter in R?

I have written a small program in R, and when I get to this following line:
i=which(grepl(yyyy.q, Metrop$year))+1
I get the following error message:
Error in grepl(yyyy.q, Metrop$year) : object 'yyyy.q' not found
I think maybe this is occurring because I haven't defined 2019.3 as the current "yyyy.q". And that is what I need to do in order to tell R to start forecasting according to my model. Does that seem like the likely problem? I thought that was the problem but have struggled to fix it.
Here is how I am defining things in the beginning of my program before I get to the actual model specification, I assume the full code isn't necessary, but happy to share if that helps.
Metrop<-Houston
name<-"National"
Metrop<-Metrop[Metrop$year>=1989.4,]
Screenshot of dataset
Thanks for you help. Happy to share any more code or data if necessary.

R build TermDocumentMatrix with removeSparseTerms parameter

Am I able to remove sparse terms WHILE creating a tm::TermDocumentMatrix object?
I tried:
TermDocumentMatrix(file.corp, control = list(removeSparseTerms=0.998))
but it does not work.
No, you cannot remove sparse terms like that with the TermDocumentMatrix function. If you check the help for that function with ?TermDocumentMatrix you'll see that the options for control are listed in the help for termFreq, and when you look at the help for that function with ?termFreq, you'll see that removeSparseTerms is not listed there. Although you have bounds which can do a related job.
If you just want a one-liner that combines TermDocumentMatrix and removeSparseTerms, you simply flip your line inside-out and that will work fine:
removeSparseTerms(TermDocumentMatrix(file.corp), 0.998)
I recommend you have a careful look at the documentation for the tm package, it's one of better examples of a well-documented contributed package. It might save you time waiting for someone to answer your questions here!

R returns NULL when trying to extract P value

I am running a PGLS loop on 1,000 trees and I am trying to extract slope, standard error, and P-values from my loop. Slope and standard error are easily extracted by using data$model$coef[2] and data$sterr[2] but the p value just does not want to come out. I have tried
1)summary(result)$pvalue which gives value NULL
2)data$model$coef[2,4] which says this is out of bounds (in fact playing around I couldn't access anything outside of the first column of coefficients without receiving the same error message)
I have tried a slew of other methods that are more or less the same idea as these two and each time I either get the dreaded NULL, the occasional NA or the out of bounds error. Does anyone know what is going on? I know we typically provide the data but this seems like a menial question (although I have spent significantly more time trying to resolve this that in my actual PGLS).
I do not think it is possible directly See this (old) question. Perhaps the easiest way is to use the summary object to extract the necessary information to calculate it yourself (via a helper function)?
See this also,

Bootstrap output matrix missing

When I try to calculate Gest in spatstat I get the error:
bootstrap output matrix missing.
Does anyone know what am I doing wrong?
I think that "bootstrap output matrix missing" is a fairly generic error, and (unless someone has explicit experience with your case) I would imagine that more information is needed to solve this.
Without more information, I would suggest that you debug the Gest function. You have two good options for that:
1) Use the debug() function:
debug(Gest)
Now run your code. Then you can walk through the Gest function and see where is breaks. Before that point, look at all the environment variables by (for instance) using ls() and see if any assumptions are broken. Presumably something isn't being set correctly.
2) Use recover:
option(error=recover)
Then you will go into browser mode whenever the error occurs, and you can explore the workspace at that point.
This error message does not originate from the spatstat package.
To identify the location of the error, type traceback() immediately after the error has occurred. This will give you a list of the nested commands that were being executed at the time the error occurred. The top one is the location which raised the error.

Resources