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

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!

Related

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

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

#Error in table(StudentSurvey$Gender, StudentSurvey$Smoke): object 'StudentSurvey' not found

So, I'm attempting to knit a R document to a HTML file however, when it knits it produces this error "#Error in table(StudentSurvey$Gender, StudentSurvey$Smoke): object 'StudentSurvey' not found"
For reference this is my R code.
read.csv("StudentSurvey.csv")
barplot(table(StudentSurvey$Gender, StudentSurvey$Smoke), legend=TRUE)
boxplot(StudentSurvey$Pulse ~ StudentSurvey$Smoke , xlab = "Smoke" , ylab = "Pulse")
I'm unsure whats wrong, I've tried to troubleshoot by changing my Rworking directory and ensure that "StudentSurvey.csv" is in there, but alas this issue appears to be happening. If it isn't immediately apparent I'm extremely new to R as I'm using it for the first time in UNI so apologies if this is a simple fix.
you just need to assign the output of read.csv() to an object.
StudentSurvey <- read.csv("StudentSurvey.csv")

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.

Not able to run selected lines in REPL R in sublime text

Followed these instructions to set up REPL for sublime text
http://www.kevjohnson.org/using-r-in-sublime-text-3/
R console is running. But I am unable to push text to console using the shortcuts
Ctrl+Shift+,,l
I must be doing something wrong here, not able to figure it out on my own. Any help appreciated.
I get the following error:
Cannot find REPL for 'regexp'
Edit: Adding sample code
library("e1071")
data(iris)
m <- naiveBayes(Species ~ ., data = iris)
m
table(predict(m, iris), iris[,5])
REPL checks scopes to know what console to run, and returns an error if no console is associated to a language. It might have been that your file was not in the R syntax.
To change the syntax : Command Panl (ctrl+shift+p), Set Syntax: R

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