Invalid specification in write.table() - r

I am encountering suddenly this odd error, which I have never come across before in write.table() command:
write.table(items,file="E:/CFA/items.dat",sep="\t",row.names=F,col.names=F)
Error in write.table(items, file = "E:/CFA/items.dat", :
invalid 'row.names' specification
When taking away the row.names argument, there is still the same error with col.names one. The data is a data frame which I have already worked with several times with no difficulties to create a .dat file. I am just puzzled.
Does anybody have a clue why it's happening now?
Thanks beforehand

Is it possible you have reassigned the F variable somewhere? Try doing it using FALSE instead of F.
write.table(items,file="E:/CFA/items.dat",sep="\t",row.names=FALSE,col.names=FALSE)

Try write.table(items,file="E://CFA//items.dat",sep="\t",row.names=F,col.names=F)
or rm(F,T) and then your command.

Related

Error in eval(expr, envir, enclos) : object 'score' not found

We have always been an SPSS shop but we're trying to learn R. Been doing some basics. I am trying to do a simple t-test, just to learn that code.
Here's my code, and what's happening:
Code screenshot
I don't get why it says "score" isn't found. It's in the table, and the read.csv code defaults to assuming the first row contains headers. I can't see why it's not "finding" the column for score. I'm sure it's something simple, but would appreciate any help.
You didn't store your imported csv file in a variable. It printed to the console because it had nowhere else to go - it just gets printed and then thrown away. You need to assign it for it to be saved in memory:
my_data_frame <- read.csv("ttest.csv")
Now your data exists in the variable my_data_frame and you can use it by supplying it as the data argument:
t.test(score ~ class, mu=0, alt="two.sided", conf=0.95, var.eg=F, paired=F, data=my_data_frame)
Also, in general, I would recommend using read_csv from the package readr over the default read.csv - it's faster.
Finally, when you ask questions, please provide your code as text, not a picture. You should also provide your data or a toy dataset - you can use the function dput to print code that will create your data, or just provide the csv file or some code that creates toy data.

Troubleshooting the XLSX Package: Row Must be Integer Vector

In my R Shiny program, I have a snippet of code as follows:
read.xlsx(wb,sheet=5,rows=5,cols=9)
When I run my program, the error it generates is as follows:
Error in read.xlsx.Workbook(wb, sheet = 5, rows = 5, cols = 9)
rows must be an integer vector else NULL or NA
What I Understand:
The workbook object "wb" has been defined. It is in no way causing the issue. I believe that declaring "rows" and "cols" is causing in issue. By using the help() function, I found that these are parameters in the function for read.xlsx. However, when I checked the online documentation, I found that the parameters called are supposed to be rowIndex and colIndex. I do not want to use parameters such as startRow because I only want a specific value.
What I Don't Understand
I don't understand what the problem is. The numbers should be vectors. In any case, when I use the as.vector command like so,
read.xlsx(wb,sheet=5,rows=as.vector(5),cols=as.vector(9))`
I get the same error. I honestly do not know where my problem is, and I hope one of you folks can help me with this syntactical issue.

Running as.Node from data.tree package in R

I'm trying to use the as.Node function from the data.tree library in R to visualize a set of media server log data as a tree. I've subset the original data frame by month and year, so that I can run one month's worth of data at a time. My function code for turning the data into a tree, and then printing it out as a .csv, is as follows:
treetrimmer2 <- function(x, y) {
urimodel <- as.Node(x)
uridf <- ToDataFrameTree(urimodel, "level", "count")
uridf <- filter(uridf, level <= y, count != 0)
filename <- paste(x$year[1], x$month[1], ".csv", sep="")
write.csv(uridf, file = filename, fileEncoding = "CP1252")
}
Some months finish without any issue. Other months, however, give me the following error (and traceback):
Error in (function () : unused argument (quote(<environment>))
7 (function ()
{
c(self$parent$path, self$name)
})(quote(<environment>))
6 self$AddChildNode(child)
5 mynode$AddChild(path)
4 FromDataFrameTable(x, pathName, pathDelimiter, colLevels, na.rm)
3 as.Node.data.frame(x)
2 as.Node(x) at media_visualizer.R#63
1 treetrimmer2(uricut$`2015.06`, 5)
Can anyone give me some guidance on what 'unused argument (quote())' means? I've tried googling it, and found that in some cases, it means that a function or term has already been defined in another context. But I'm still too novice to understand what that means here.
I'm running rStudio 0.99.896 and R 3.2.4 on Mac OS 10.11.5. I would share my data set, except that it is pretty massive, and I'm not sure which lines are causing the problem...
I can't claim credit for this; Christoph Glur (see the comments on the main post) figured it out. But it might be useful for others to share the cause, and my solution:
The problem is that a few of the log files contain one of the data.tree package's reserved words, in this case, "path". The format of the lines was "/something/something/path/something/something.jpg", so that data.tree read "path" as an independent word. There were other instances of "path" as part of a larger word, e.g., "pathString" or "pathTo", that didn't cause the bug.
Once he'd figured it out, my solution was to run the following command on all of the log files in Terminal:
sed -i '' 's/\/path\//\/spath\//' *.log
I'm still a novice, but as I understand it, what that means is "find and replace, in place, instances of "/path/" with "/spath/" in all of the .log files." I don't actually care about that one word, path vs. spath (which is gibberish), so changing it didn't matter. And now the as.Node() function runs properly on the data set.
Thank you, Christoph!

R Language: Error in read.table(file.path(data.dir, file_name1)) : no lines available in input

I am having a hard time coding in R language. What I am trying to do is read large amount of data in to one data frame, and make pretty pictures.
This is what I have:
# assign data
file_name1<-"data1_txt"
file_name2<-"data2_txt"
data.dir<-"/...../Documents/R programing Language/"
for(i in 1:length(1)){
newData1<-read.table(file.path(data.dir, file_name1))
#Replace negative numbers with NA
xx <- which(datavalues<0)
datavalues[xx] <- NA
newData2<-read.table(file.path(data.dir,file_name2))
}
Error I have is:
Error in read.table(file.path(data.dir, file_name1)) :
no lines available in input
I am trying to figure out by myself, but I am very new to R language, and I don't have enough knowledge of functions in R. Please explain what this error means and advice on my coding.
Thank you very much,
Uka
Similar situation was solved here with similar question (I know this post is quite old). Recently I got such error parsing several files... The reason was some files were empty which makes sense of error message.
Anyway, just make sure your input will not be empty using try ou trycatch as suggested on mentioned link.

Kindly check the R command

I am doing following in Cooccur library in R.
> fb<-read.table("Fb6_peaks.bed")
> f1<-read.table("F16_peaks.bed")
everything is ok with the first two commands and I can also display the data:
> fb
> f1
But when I give the next command as given below
> explore_pairs(c("fb", "f1"))
I get an error message:
Error in sum(sapply(tf1_s, score_sample, tf2_hits = tf2_s, hit_list = hit_l)) :
invalid 'type' (list) of argument
Could anyone suggest something?
Despite promising to release a version to the Bioconductor depository in the article the authors published over a year ago, they have still not delivered. The gz file that is attached to the article is not of a form that my installation recognizes. Your really should be corresponding with the authors for this question.
The nature of the error message suggests that the function is expecting a different data class. You should be looking at the specification for the arguments in the help(explore_pairs) file. If it is expecting 2 matrices, then wrapping data.matrix around the arguments may solve the problem, but if it is expecting a class created by one of that packages functions then you need to take the necessary step to construct the right objects.
The help file for explore_pairs does exist (at least in the MAN directory) and says the first argument should be a character vector with further provisos:
\arguments{
\item{factornames}{an vector of character strings, each naming a GFF-like
data frame containing the binding profile of a DNA-binding factor.
There is also a load utility, load_GFF, which I assume is designed for creation of such files.
Try rename your data frame:
names(fb)=c("seq","start","end")
Check the example datasets. The column names are as above. I set the names and it worked.

Resources