Why am I receiving "plow.new has not been called yet" when trying to plot PCAs? - r

This is the end goal however when trying to plot the code below
plot(PCAloadings[,1:2], arrows(0,0,PCAloadings[,1],PCAloadings[,2]), text(PCAloadings[,1:2], labels=rownames(PCAloadings))
I recieve the following error:
in text.default(PCAloadings[, 1:2], labels = rownames(PCAloadings)) : plot.new has not been called yet
I am unsure how to resolve this issue or what it pertains to, any help is welcome.
EDIT: when trying to run line by line only the first line runs. When trying to run arrows or text lines I run into the same error
plot(PCAloadings[,1], PCAloadings[,2])
This is the output from the first line alone

Seems to be a syntax problem. Try
plot(PCAloadings[,1:2])
arrows(0,0,PCAloadings[,1],PCAloadings[,2])
text(PCAloadings[,1:2], labels=rownames(PCAloadings))

Related

How to stop R from stopping execution on error?

I'm having an issue where if I execute several lines of code at once and one of them has an error, the lines below don't get executed.
For example if I have:
table(data$AGE)
table(dataREGION)
table(date$SEXE)
I get the table for the first line, and then
Error in table(dataREGION) : object 'dataREGION' not found
>
And the last line does not execute.
Does anyone know why it does that and how to fix it?
(I work with R 4.2.2 and RStudio 2022.12.0+353 "Elsbeth Geranium" Release)
Thanks!
Have a nice day,
Cassandra
Fixed: In Global Options > Console, under "Execution" uncheck the "Discard pending console input on error"
It seems like you want to use try().
try(table(data$AGE), silent = F, outFile = T)
try(table(dataREGION)) # also works without any params
try(table(date$SEXE))
You can also use tryCatch() if you want more control but it doesn't seem necessary for your purpose.
__
As for why your dataREGION doesn't exectue:
Hazarding a guess it might be because you forgot the $ between data and REGION

grDevices::dev.new() does not work in the first time

My question: How to let grDevices::dev.new() work well ?
To avoid the error Error in plot.new() : figure margins too large coursing the small plot region,
I wrote the code grDevices::dev.new() in the front of plot().
However this code does not work in the first time (or after pushing the button .clean all plot button )
And this cause the errors (e.g., in the R CMD check).
Do I misunderstand the function grDevices::dev.new() ?
REF?:
R: Open new graphic device with dev.new() does not work
Answer
Using grDevices::windows() instead of grDevices::dev.new(), I overcome the issues.
Unfortunately, we cannot use grDevices::windows() , because the following error occurs in the R CMD check:
Error in grDevices::windows() :
screen devices should not be used in examples etc

Error in `[.data.frame`(t, 1) : undefined columns selected

I got this R code to make visualization using ggplot. However, I am getting the problem with syntax. Can anyone see where it went wrong? Thanks!
t <- ggplot_build(p)$data[[3]]
s[i,1] <- as.character(a[i])
s[i,2] <- t[1,2] - t[(length(t[,1])),2]
The error is related to t in this three lines of code.

ggsave error: cannot find function "dev"

I get the following error when trying to save my ggplot:
Error in ggsave(paste0(projDir, "figs/lmGtaGridCombined.png")) :
could not find function "dev"
This was code that worked earlier this year, before the newest ggplot(2.0.0). The 3rd party code I'm using (https://rpubs.com/Koundy/71792; which uses ggthemes) worked great earlier this year to make my images more publication-friendly. However, now the ggthemes code gave errors related to:
Error in FUN(X[[i]], ...) :
Theme element 'text' has NULL property: margin, debug
In addition: Warning message:
`axis.ticks.margin` is deprecated. Please set `margin` property of `axis.text` instead
>
which I thought I fixed by changing this line:
text = element_text()
to this:
text = element_text(margin=margin(), debug= F),
which made a version of my image print, but many aspects (ie, x-label spacing flush instead of offset) not right. Plus- ggsave gave the above error, which is now my biggest problem, as I am considering manually fixing the image if I can just get it to print similarly to as it did before.
I've tried png ..... dev.off but I can't get it to print in the right dimensions and resolution as it did originally with ggsave.
Please help. I've been scared to post on stackoverflow up until now, but I'm very desperate. Thanks in advance.

I get error when I use zip.au3 and console.au3 together in an autoit script

I get the following error when I use zip.au3 and console.au3 together. To simulate this error please create a new script in SciTE script editor and include zip.au3 and console.au3 and then run it (just two include lines are sufficient to simulate). You will get two pop up messages.
Here are the error messages:
First Popup message:
AutoIt Error:
Line 456 (File "C:\Program Files (z86)|AutoIt3\Include\zip.au3:):
$ZipFile=#ZipSplit[2]
$ZipFile=^Error
Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.
Second popup message:
Line 455 (File "C:\Program Files (z86)|AutoIt3\Include\Console.au3:):
If $_Amount_Startup_COnsole Then If^Error
Error: Variable used without being declared.
(I would like to attach zip.au3 and console.au3. How can I do it? They are available for download rom Autoit Forum - Example scripts)
Regards,
Nazir
As far as i can see, the Problem is that the Zip.au3 starts a function at startup which it should not do.
If you delete the first Lines in Zip.au3 then it should work fine:
If UBound($CMDLine) > 1 Then
If $CMDLine[1] <> "" Then _Zip_VirtualZipOpen()
EndIf
So my AutoIt dont gives back any Error Messages anymore. But I'm not sure if the other functions will work now. Try it out.
Teifun2
PS: sorry for my bad english!

Resources