'"Error in file(file, "r") : cannot open the connection"
I'm trying to conduct CFA but suddenly this error appear and now I cannot use r anymore since no metter what data I use it always give me the "Error in file(file, "r") : cannot open the connection". This is the code that I'm using right now: data
data <- read.delim("C:/Users/Nyname/Desktop/data.txt")
View(data)
model
overall_data <- '
f1 =~ item_3 + item_4 + item_12 + item_16
f2 =~ item_1 + item_5 + item_9 + item_14 + item_18
fit
overall_datafit <- cfa(overall_data, data=data, meanstructure = TRUE)
Error in file(file, "r") : cannot open the connection
I'v tried to change the directory, using setwd() and to unistall and install but nothing seems to work. I really hope somebody can help me because I've no idea what to do next and I really need to finish my work. Thank you
Solution 1:[1]
I also came across similar kind of error when I worked on windows, and was not able to resolve what was the problem with my code.
If you are windows below will help, as I finally found out what the problem actually was:
When you name your file "blabla.txt" then windows name it "blabla.txt.txt"... That's the same with .CSV files so windows create a file named "bla.csv.csv" if you called it "bla.csv"
So, when you create your .txt file, just rename it "data" and open it in R using data <- read.delim("C:/Users/Nyname/Desktop/data.txt")
It worked for me.
Solution 2:[2]
It is a bit late for answering this question, but others may also face it.
It is possible that you have loaded another package that masks the function cfa() from lavaan (e.g., package "sem" or other packages that require it such as "faoutlier"). If so, you will face this error.
If this is the case, using lavaan::cfa() instead of cfa() should resolve the problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ashwin agrawal |
| Solution 2 | Ali Zia-Tohidi |
