Unable to launch ggplot graphs on Kaggle, always get 'Error in parse(text = x, srcfile = src): attempt to use zero-length variable name Traceback': - r

I had my Rmrkdown file running well on Rstudio and got knit to html fine.
And it could also be saved successfully on Kaggle with all R and Notebook options ensured.
It just can show the graphs on Kaggle. Can help?
My file is here to share https://www.kaggle.com/helenchoi/bellabeat-marketing-for-spring-assignment?scriptVersionId=75128488 , please advise. Thanks.
Helen

Related

How to solve TIFFOpen Error Popup in RStudio?

I am running spThin from the package "spThin" in RStudio
I am trying to save the plot generated from plotThin function
Following is my code after the spThin function:
tiff(file = paste(n, "plotThin2.tiff", sep = "_"))
plotThin(ca.thin, which = 2)
dev.off()
However, I get /n_plotThin2.tiff: Cannot Open.
I don't think it is the issue with my code as I went the code another 2 computers without problem but only this computer
If I switched from tiff to jpeg()
I get Error during wrapup: unable to start jpeg() device
I am running R 3.6.2
Can someone help please. Thank you

R/ RStudio: Error in file(file, "r") : cannot open connection // German // Macbook Air

I'm trying to do a confirmatory factor analysis on R for the first time.
I've researched this error and nothing helped so far (changing the working directory and so on).
Creating my model worked. But when I try to run the "fit" I get the error with
"Error in file(file, "r"): cannot open connection".
My first data frame is saved in "downloads" folder of my Mac. But I'm working with data Frame "data4" which is saved in a different folder. data4 is in the same folder as the whole project. It seems like the error has something to do with the path.
I also tried:
fit <- cfa(model, data = "~/Documents/BACHELORARBEIT/Daten/data4.RData, missing = "ML")
instead of:
fit <- cfa(model, data = data4, missing = "ML")
but I still get the same error message.
thank you in advance!!!
It seems you have set up the wrong working direction.
The easiest Solution would be to put all your files and the script in the same folder and just use on the toolbar:
Session -> Set working direction ->to source file.
Or check this post and see it can
help.

Issue trying to Knit Rmd File to Word when RWeka is Used

I'm trying to Knit an Rmd file to Word, and keep encountering the following error message:
Error Message from RStudio
My line 28 is as follows:
NN <- make_Weka_filter("weka/filters/unsupervised/attribute/NumericToNominal")
I use NN later to apply the filter function to my testing and training data (I'm attempting a classification model for the Federalist papers)
trainfed <- NN(data=trainfed, control= Weka_control(R="1-3"), na.action = NULL)
testfed <- NN(data=testfed, control= Weka_control(R="1,3"), na.action = NULL)
When I run all of this either in blocks in my instance of RStudio, or just line by line - I have no issues. I can view the output in window, in line, and even in the viewer pane.
However, as soon as I start to try to Knit to Word I get the error mentioned above.
Is it possible to Knit to Word with RWeka package in use? I've seen many of these filed, but never really one with an answer to the error in finding the function on whatever instance Rmarkdown Knits from...
Can anybody advise? Thank you!

Error in file(con, "w") : cannot open the connection [Using R-Studio to plot interactive bar graphs using rCharts, knitr]

I am getting an error when I am trying to run the code below in R-Studio 3.3.2 on a Mac (OS Sierra)
devtools::install_github('ramnathv/rCharts')
install.packages("knitr")
require(rCharts)
require(knitr)
haireye <- as.data.frame(HairEyeColor)
n1 <- nPlot(Freq ~ Hair, group = 'Eye', type = 'multiBarChart',
data = subset(haireye, Sex == 'Male')
)
n1$save('fig/n1.html', cdn = TRUE)
cat('<iframe src="fig/n1.html" width= 100%, height=600</iframe>')
Pls see output below:
Error in file(con, "w") : cannot open the connection
In addition: Warning message: In file(con, "w") : cannot open file 'fig/n1.html': No such file or directory
But I am able to generate the reqd bar graph in the viewer when I use:
n1$show(cdn = TRUE)
in lieu of n1$save('fig/n1.html', cdn = TRUE)
To take care of write permission issues (if any), I also tried including the line below, altering the WD path wherever necessary.
knitr::knit2html('Users/documents/n1.html')
But it did not help. I see the n1.html file created but it only opens an empty browser.
Any help to resolve this is appreciated.
Best,
S
A lot of times we face this error due to caching in RStudio and in that case, actual code errors don't show up. Restart RStudio and this error will be gone and actual code errors would show.
You have two separate problems.
The connection error appears because the fig/ folder does not exist. Create the folder and the save command will work. R has functions to check the existance of directories and create new ones if you would like to do it in your code.
The second problem comes from the way you save, you should use n1$save('fig/n1.html', standalone = TRUE). Here you have a similar situation.
As a side-note, I would say rCharts is not currently developed or mantained at all, so I would recommend you to use another library for your charts. In my opinion Plotly is quite nice. rCharts brought the NVD3 project to R and the chart style is in my opinion really nice. However, as far as I know both projects are stopped so I would look for a library that is still alive.
I have fixed this problem with good old rm(list=ls()) . I know I have
fallen into sequences where the error stops execution of my script. I fix the error, and then it won't run. This is likely due to lazy evaluation but it is a near impossible problem to diagnose, so the solution at the top works almost all the time.

Error in R. Error in gsub("(?<=\n)(?=.|\n)", continue, x, perl = TRUE) :

I am encountering an error in R that I cannot seem to figure out. I am creating an R markdown document where I read in an a csv table using this code.
iati <- read.csv(file="/filepath/IATI_NGOS.csv",head=TRUE,sep=",")
and then using ggplot2 I create a plot using the following code.
figure_one <- ggplot(iati, aes(iati$reporting.org))+
geom_bar(fill="blue")+
ylab("Total Activities")+
xlab("NGO Reporting Organizations in IATI")+
ggtitle("Total Number of Activities compared to each NGO Reporting Organization in IATI")+
coord_flip()
When I try to call figure_one in the R markdown I get the following error:
Quitting from lines 44-55 (NGO_IATI.Rmd)
Error in gsub("(?<=\n)(?=.|\n)", continue, x, perl = TRUE) :
input string 1 is invalid UTF-8
Calls: <Anonymous> ... paste -> comment_out -> line_prompt -> paste -> gsub
In addition: Warning message:
In grep("\n", message) : input string 1 is invalid in this locale
Execution halted
When I run this code in a regular R script I have absolutely no issues. I have search for some answers but can't figure it out.
Thanks!
I ended solving my issue by just doing a fresh install of R and Rstudio on my local machine. I think the recent update to Yosemite on my local environment created a lot of issues with the TeX plugin I had installed for R markdown.
I get the same question when I knit my rmarkdown document and find **encoding is the cause.
When you use functions like read.csv, fread or read_csv, you will read the column name.
If column names are in other languages, like Chinese, the problem will easily happen.
Or you rmarkdown works on Windows, but the encoding bug happens on Mac, a different environment.
The temporal solution is to rename the column name in English and resave the data files.
Here is the pseudocode in R to show my idea.
library(data.table)
library(tidyverse)
fread('yourfile.csv',encoding = 'UTF-8') %>%
purrr::set_names(c('x1','x2','x3')) %>%
write_excel_csv('yourfile_2.csv')
Here the new file yourfile_2.csv is fine to rmarkdown knit without encoding problems happening.

Resources