I have the same problem with this one but no solutions found yet
.
Error in if (more || nchar(output) > 80) { : missing value where TRUE/FALSE needed
I am conducting analysis using the mgcv package.
model1<-gam(fm_xsetz~total_pm2.5, data=analysis)
I can get the results by using the summary(). But when I try to open the model in the global environment, I get the warning:
Error in if (more || nchar(output) > 80) { : missing value where
TRUE/FALSE needed
Is anyone has the same problem?
FYI,when you use the following code:
library(geostatsp)
data(swissRain)
same problem happens!
I have/had a similar problem when I tried to view a List generated trough a function that computes the intersect/difference of two sets of 23000 observations each.
The function in question:
jeepers.creepers<-function(dfx,dfy,by.x,by.y){
SetX<-dfx[[by.x]]
SetY<-dfy[[by.y]]
Union.X.Y<-intersect(SetX,SetY)
Difference.in.X<-setdiff(SetX,Union.X.Y)
Difference.in.Y<-setdiff(SetY,Union.X.Y)
result<-list(Union.X.Y,Difference.in.X,Difference.in.Y)
names(result)<-c("Union of SetX and SetY",
"Unique in SetX",
"Unique in SetY")
return(result)
}
It gave me this error:
Error in if (more || nchar(output) > 80) { :
missing value where TRUE/FALSE needed
Nevertheless I could view the elements individually with
View(list$element)
I had a similar problem yet I could view it with:
view(as.data.frame(df))
Related
I've used below code which successfully compares two text files and logs the difference in a log file using for loop. The file names are in series, for example, File_1, File_2 etc.. but when there is a missing file in the series, the code stops the execution with error - No such file or directory.
Then I've used if condition to check the file existence but I am getting a below-mentioned error.
Please help me to skip comparison for a nonexisting file.
Code:
for(i in 1:length){
prod_file_res_name <- sprintf("path/Query_Prod_%s.txt", i)
beta_file_res_name <- sprintf("path/Query_Beta_%s.txt", i)
if (exists('prod_file_res_name' && 'beta_file_res_name')){
res <- tools::Rdiff(prod_file_res_name, beta_file_res_name, Log = TRUE)
if(res[2] != "character(0)"){
write(toString(res[2]), file = "LogFile.txt",append=TRUE)
}
else{
elsevar <- sprintf("No difference found between prod and beta responses for query %s", i)
print(elsevar)
}
}
}
Error:
Error in "prod_file_res_name" && "beta_file_res_name" :
invalid 'x' type in 'x && y'
exists checks if the given R objects (only takes R objects as input --> this caused your first error) exist in your environment. You initiate the R objects prod_file_res_name and beta_file_res_name before you check if they exist, so the exists call will always return TRUE. What you are looking for is the file.exists function which checks if the file does exist in your working directory:
file.exists(prod_file_res_name) && file.exists(beta_file_res_name)
The second error was caused by the R objects existing but not the files you want to check.
Since exists() looks up single objects (from Documentation):
Is an Object Defined?
Description
Look for an R object of the given name and possibly return it
'prod_file_res_name' && 'beta_file_res_name' doesn't work.
Rewrite
exists("prod_file_res_name" && "beta_file_res_name")
to:
exists("prod_file_res_name") && exists("beta_file_res_name")
I have some problems with the viterbiTraining function from the HMM package.
I tried using it on a pretty straightforward hmm and a vector of observations.
Here's the code:
Emisije<-rep("IntervalC",length(Cl1.res))
Emisije[IntervalA[,1]]<-"IntervalA"
Emisije[IntervalB[,1]]<-"IntervalB"
The Emisije vector looks like this:
head(Emisije)
[1] "IntervalA" "IntervalA" "IntervalA" "IntervalC" "IntervalB" "IntervalA"
startProbs<-c(0.6873065,0.3126935)
transProbs<-matrix(c(0.8, 0.7, 0.2,0.3),ncol=2)
emissionProbs<-matrix(rep(1/3,6),ncol=3)
stanji<-initHMM(c("NizkaVar", "VisokaVar"), c("IntervalA", "IntervalB",
"IntervalC"), startProbs, transProbs, emissionProbs)
After running this everything works, except for the viterbiTraining function, which gives the following result:
viterbiTraining(stanji,Emisije)
Error in if (d < delta) { : missing value where TRUE/FALSE needed
Even the similar function baumWelch, which takes the exact same parameters, works without errors, so I really don't understand what's wrong here.
Can anyone please explain to me what I am doing wrong? Thank you in advance.
Program : R 3.2.1 for Mac OSX
IDE : RStudio
Output : rmkd > html
Package : "psych"
Function : alpha()
Problem :
While using alpha(data, na.rm=F, check.keys=F, delete=F), because portions of the input-data is negatively correlated and because I have check.keys = FALSE, I get the following message :
Some items XXX were negatively correlated with the total scale and
probably should be reversed. To do this, run the function again with
the 'check.keys=TRUE' option
Question :
My check.keys is set intentionally. Fully understanding the implications of the warning & mostly for aesthetic and educational reasons, how can I suppress it in my output?
Attempts so far :
1. I've tried suppressWarnings() & suppressMessages().
2. I've tried invisible() & sink(., type="message").
3. In the Rmd block, I've tried : ```{r warning=F, message=F}
4. Exploring print(alpha) I found what I think is the origin. Maybe someone understands how to suppress this part of the code? :
`p1 <- principal(x)
if (any(p1$loadings < 0)) {
if (check.keys) {
warning("Some items were negatively correlated with total scale and were automatically reversed.\n This is indicated by a negative sign for the variable name.")
keys <- 1 - 2 * (p1$loadings < 0)
}
else {
warning("Some items were negatively correlated with the total scale and probably should be reversed. To do this, run the function again with the 'check.keys=TRUE' option")
cat("Some items (", rownames(p1$loadings)[(p1$loadings < 0)], ") were negatively correlated with the total scale and probably should be reversed. To do this, run the function again with the 'check.keys=TRUE' option")
}
}`
thanks!
The culprit here is cat, which will not heed suppressMessages etc.
To catch it, you can use capture.output instead:
invisible(capture.output(alpha(data, na.rm=F, check.keys=F, delete=F)))
capture.output calls sink(…, type = "output") internally and discards/returns the result.
This is a follow-up to removeSource() returning error on internal package function.
In that question, it was pointed out that there may be a bug in removeSource() when the function uses [ subsetting. I want to focus on that issue, so I wrote a new question here.
When the j argument in [ is empty, removeSource() fails.
Here's an example.
foo <- function(x) { x[1, ] }
removeSource(foo)
# Error in recurse(part[[i]]) : argument "part" is missing, with no default
bar <- function(x) { x[1, seq_along(x)] }
removeSource(bar)
# function (x)
# {
# x[1, seq_along(x)]
# }
I'm hesitant to call it a bug, so I'll first ask if this was done intentionally? Also, suppose I submitted the foo() function in a package to CRAN. Would it pass the testing?
Updates:
Sept 1, 2014: Bug report filed https://bugs.r-project.org/bugzilla/show_bug.cgi?id=15957
Sept 21, 2014: This was indeed a bug and according to the confirmed bug report is "soon to be fixed in R-devel and R-patched."
Fixed in version R 3.1.2
I'd say it was a bug. No sign of it reported here though:
https://bugs.r-project.org/bugzilla3/buglist.cgi?quicksearch=removeSource
Interestingly you get a different error once you try and debug the function by making a local copy.
> dput(removeSource,file="rs.tmp.R")
> rs = dget("rs.tmp.R")
rs is now a copy of removeSource, but not in the environment of the utils package.
> foo = function(x){x[1,]}
> rs(foo)
Error in `attr<-`(`*tmp*`, "srcref", value = NULL) : '*tmp*' is missing
> removeSource(foo)
Error in recurse(part[[i]]) : argument "part" is missing, with no default
rs works fine on a function without missing subs:
> bar = function(x){x[1]}
> rs(bar)
function (x)
{
x[1]
}
If you want a really minimal failing example, you don't need any subscripts or commas:
> foo = function(x){x[]}
> removeSource(foo)
Error in recurse(part[[i]]) : argument "part" is missing, with no default
I doubt this will trigger any CRAN flags since missing dimensions in subscripts probably occur in 90% of the packages currently on there...
Suggest you report it on the bug tracker, or ask on R-devel mailing list.
I get an Argument is of length zero error when I run the below code
The code is from this blog -http://giventhedata.blogspot.in/2012/08/r-and-web-for-beginners-part-iii.html.
library(XML)
url<- "http://news.bbc.co.uk/2/hi/uk_politics/8044207.stm"
first<-"Abbott, Ms Diane"
url.tab <- readHTMLTable(url)
for (i in 1:length(url.tab)){
if (as.character(url.tab[[i]][1,1]) == first ) {print(first)}
}
I know that the url.tab[[5]][1,1]) does contain the string "Abbott, Ms Diane", and when I run IF statement in isolation replacing the i with 5, it runs fine. Any help would be appreciated. I also tried declaring i<-1 upfront. DInt change anything.
Some of your tables are in fact NULL.
So you have to test for is.null before trying to subset the table:
for (i in 1:length(url.tab)){
this.tab <- url.tab[[i]]
if(!is.null(this.tab)) if(as.character(this.tab[1,1]) == first ) {print(first)}
}
[1] "Abbott, Ms Diane"