I am trying to run a Confirmatory Factor Analysis (part of the SEM package) in R but part of the syntax consists of using (<->) double-sided arrows. However, when I write "<->" in R, the program does not run and I get this: "Error: unexpected '>' in "amsex1<->" Thanks for your help!
library(SEM)
data<-read.csv("C:/Users/cgonzal6/Desktop/CYRUS/pilot-2-measurement13.csv")
factor<-data.frame(cbind(amsex1,amsex2))
cov.matrix<-cov(na.omit(factor))
cfa.model<-specifyModel()
EXTERNAL->amsex1,external0
Introjected -> amsex2, introjected0
amsex1<-> amsex1, error1
amsex2<-> amsex2, error2
The specifyModel() function reads the user input from the command line. It must be running in interactive mode to work. The <-> is not R syntax and should not be run as R code; that's just how specifyModel() wants' the model to be described in a text format. You can interpret everything after the specifyModel() to the next blank line as a big long character variable.
I assume you're trying to source() this script or run it from the command line? In a non-interactive mode, you can save the model specification in a file and read it with specifyModel(file="filename.txt"). That should also work in interactive mode as well.
Related
When I open a .R file and highlight a line and press Shift + Enter, VS code sends the line to R, but it mangles the text. For example, if I try to run
library(data.table)
Here is what I get back from R:
> 00~library(data.table)01~
Error: unexpected numeric constant in "00~library(data.table)01"
Strangest thing. VS Code works fine for me for Go, Typescript, Haskell, Python, but it doesn't like R. Any suggestions?
It looks like bracketed paste mode is on. Try adding this to your settings.json:
"r.bracketedPaste": false
Bracketed paste mode should usually be on if using the radian console but off if using the standard R console.
I'd like to run R as an inferior process. I'd like R to display help pages as html (in the browser) and to display plots as if it were run interactively. I know I can run R with the --interactive argument but then R seems to assume it's running on a terminal end emit control sequences.
How should I run R to get html help pages & plot (as with --interactive) and simple textual output with no control sequences?
If I use R, it assumes to be run non-interactively (html help pages or plots won't work but the output contains no control sequences).
If I use R --interactive --no-readline, it runs interactively (help pages and plots work as expected) but the output is garbled and difficult to parse since it assumes to be running on a terminal.
Is there a way to control the assumptions R makes about the terminal it's running in?
It seems that argument order matters. (Part of) the problem gets resolved when calling R as R --no-readline --interactive.
I am sending passing R scripts to R from Tableau and would like to be able to see the result in the R console. I have got this to work in the past, but not sure how to do it again.
In R I've ran the following lines of code:
Note, [Petal Length] is just a column of number values- it doesn't matter what the numbers are. In this case I just got it from the IRIS dataset (which is pre-packaged in R as you can see if you run data())
install.packages("Rserve")
library(Rserve)
run.Rserve()
In Tableau, the calulated field that contains the R script is:
SCRIPT_INT('print(.arg1)', SUM([Petal length]))
Thanks.
After some searching I finally found the answer to this question. 1) you have to have the function print() in the Tableau calculated field, and 2) you have to use the command: run.Rserve() as opposed to Reserve().
I have a network in R, formatted in pajek(.net) of collaborations. I'm trying to run an ergm analysis on it. I've formatted a similar network and run the same commands successfully, but when we expanded the size of the network, this error has begun to appear.
> CollabNet2005ERGM <-ergm(CollabNet05~edges+nodematch("11"))
Error in -object$glm$null.deviance : invalid argument to unary operator
Is there a workaround, either on the formatting side of things or within R that will allow me to complete the ERGM?
I have a simple R script doing:
jpeg(myplot.jpg)
x<-seq(1,20,0.1)
y<-sin(x)
plot(x,y)
dev.off()
After execution it makes a myplot.jpg file in /root/work/ but renders gibberish information and does not plot a legible graph.
Also how can I view the graph in R shell itself?
The first argument to jpeg should be a character string, so I wouldn't expect your code to work unless myplot.jpg contained a character string. This works fine for me:
jpeg("myplot.jpg")
x<-seq(1,20,0.1)
y<-sin(x)
plot(x,y)
dev.off()
Whether you can view the graph in the "shell" depends on the R console you're using. If you're running R from bash, sh, etc, the answer is "no, you can't view a plot directly"... actually it wouldn't surprise me if there was a package that allowed you to create text-plots, but I don't think that's what you want.