R: Running stan() function get some errors: - r

when I am running the stan() function I get two errors about Error in file(con, "r") : cannot open the connection and Error in sink(type = "output") : invalid connection. BTW, my .stan file is correct. Please help.
> rstan:::rstudio_stanc("8schools.stan")
8schools.stan is syntactically correct.
> schools_dat <- list(J = 8,
+ y = c(28, 8, -3, 7, -1, 1, 18, 12),
+ sigma = c(15, 10, 16, 11, 9, 11, 10, 18))
> fit_8schools <- stan(file = 'C:/Users/.../Desktop/8schools.stan', data = schools_dat)
The NEXT version of Stan will not be able to pre-process your Stan program.
Please open an issue at
https://github.com/stan-dev/stanc3/issues
if you can share or at least describe your Stan program. This will help ensure that Stan
continues to work on your Stan programs in the future. Thank you!
This message can be avoided by wrapping your function call inside suppressMessages().
Error in file(con, "r") : cannot open the connection
In addition: Warning messages:
1: In file.remove(c(unprocessed, processed)) :
cannot remove file 'C:\Users\lpb\AppData\Local\Temp\RtmpW6qdvg\file1f7436407ba4.stan', reason 'No such file or directory'
2: In system(cmd, intern = !verbose) :
running command 'D:/ProgramFiles/R-4.0.2/bin/x64/R CMD SHLIB file1f741c6e1040.cpp 2> file1f741c6e1040.cpp.err.txt' had status 1
3: In file(con, "r") :
cannot open file 'file1f741c6e1040.cpp.err.txt': No such file or directory
Error in sink(type = "output") : invalid connection
> setInternet2(TRUE)
Error: 'setInternet2' is defunct.
See help("Defunct")

Related

How to correctly use readWave in Rstudio

Im getting this error while executing this line in RStudio, I have tuneR lib installed.
birds <- readWave("birds.wav")
Error in readBin(con, int, n = 4, size = 1, endian = "little", signed = FALSE) %*% :
non-conformable arguments
In addition: Warning message:
In readChar(con, 4, useBytes = TRUE) : truncating string with embedded nuls
Tried to look for examples and can´t find any that helps me.

Re-run chunk automatically if error occurs in R [duplicate]

I have the following API call function:
df.load <- loaddf(r = as.character(readline(prompt = "Please enter r parameter: "))
,y= as.character(readline(prompt = "Please enter y parameter: "))
,z= as.character(readline(prompt = "Please enter z parameter: ")) )
,format="json"
# Convert to dataframe
data.df <- as.data.frame(df.load )
However, sometimes it fails to connect:
Warning in file(file, "rt") :
InternetOpenUrl failed: 'A connection with the server could not be established'
Error in file(file, "rt") : cannot open the connection
and a number of observations in the final dataframe data.df is equal to 0, but when I re-run the code 3-4 times, it works.
Therefore I want to push R to re-run this chunk in the .rmd file if the connection failed or a number of observations are equal to 0 in data.df.
Or if you have any other ideas on how to solve this issue I am open to your suggestions.
Thanks

Create a dtm using tokens

I try to run tis command
dtm <- CreateDtm(tokens$text,
doc_names = tokens$ID,
ngram_window = c(1, 2))
However I receive this error:
Error in seq.default(1, length(tokens), 5000) :
wrong sign in 'by' argument
In addition: Warning message:
In CreateDtm(tokens$text, doc_names = tokens$ID, ngram_window = c(1, :
No document names detected. Assigning 1:length(doc_vec) as names.
Any idea what I have to change in order to run it properly?

R Studio not responding to the names() command

I am writing the following below. R studio would send an error message:
Error: unexpected input in "names(mancova)= c(�
in resonse to the line where I give new names to the columns:
names(mancova)= c(“GPID”, “Precomp”, Postcomp”, “Posthior”)
Here is the full code:
install.packages("MASS")
install.packages("car")
install.packages("psych")
install.packages("Rcpp")
library(MASS)
library (car)
library(psych)
group1 = matrix(c(1,15,17,3,1,10,6,3,1,13,13,1,1,14,14,8,1,12, 12, 3, 1, 10, 9, 9,1,12,12,3,1,8,9,12,1,12,15,3,1,8,10,8,1,12,13,1,1,7,11,10,1,12,16,1,1,9,12,2,1,12,14,8), nrow=15,ncol=4, byrow=TRUE)
group2=matrix(c(2,9,9,3,2,13,19,5,2,13,16,11,2,6,7,18,2,10,11,15,2,6,9,9,2,16,20,8,2,9,15,6,2,10,8,9,2,8,10,3,2,13,16,12,2,12,17,20,2,11,18,12,2,14,18,16),nrow=14,ncol=4,byrow=TRUE)
mancova = data.frame(rbind(group1, group2))
names(mancova)= c(“GPID”, “Precomp”, Postcomp”, “Posthior”)
attach(mancova)
mancova
options(scipen=999)
outcome = cbind(mancova$Postcomp, mancova$Posthior)
model = manova(outcome~GPID+Precomp+GPID*Precomp, data=mancova)
summary(model, test=“Wilks”, type=“III”)
factor(GPID)
modelA = aov(Postcomp~Precomp+GPID, data=mancova)
summary(modelA, type=“III”)
library(effects)
adjmeanA = effect(“GPID”, modelA, se=TRUE,xlevels=2)
summary(adjmeanA)
adjmeanA$se
Its written in the error itself:
Error: unexpected input in "names(mancova)= c(�
The last symbol is unknown to R, which is an italic/cursive version of the quotes. " " is defined/valid. " " is not.

Error when reading/writing in the temp directory (using arulesSequences in R-studio)

When I run the following code:
s1 <- cspade(x, parameter = list(support = 0.1, maxsize = 1, maxlen = 1),
control = list(verbose = TRUE))
I receive the following error:
Total elapsed time 0.00286102
1 partition(s), 0 MB [0.12s]
mining transactions ...MINSUPPORT 1 out of 4 sequences
reading sequences ...cannot open file
'C:\Users\ERKANE~1\AppData\Local\Temp\RtmpohPsWy\cspade3894f1b4b9f.out': No
such file or directoryError in file(con, "r") : cannot open the connection
When I check the directory, I do not see any .out file. I have attempted to change the TMPDIR to another location, but still received the same error. I run r-studio as admin, but still receive the same error. I am able to create a file in the same directory write.csv(mtcars,paste(tempdir(),"mtcars.csv",sep="\\")). Any ideas?
I am using R version 3.5.1 and RStudio-1.1.456.

Resources