R error in write.table >> Error in sc[[length(sc) – 7L]][[1L]] == “example”

Issue

This Content is from Stack Overflow. Question asked by JT_geospatial

I have a data.table object named dat where if I try write.table(dat,'test.txt'), I get this bizarre error:

'Error in sc[[length(sc) - 7L]][[1L]] == "example": comparison (1) is possible only for atomic and list types'

Following the stack trace takes me to cedta.R

cedta.R is way over my head. What is going on here and how do I address this issue?

In context, I read some data from a text file with fread(), then I select some rows from the table using a conditional, then I want to write the filtered table to a new text file. Pretty simple, I’m very confused what’s wrong here.

dat <- fread(ptx, skip = 10, header = FALSE)
names(dat) <- c("X", "Y", "Z", "Intensity", "R", "G", "B")
ptx_header = readLines(ptx,n=2)
ncols = as.integer(ptx_header[1])
nrows = as.integer(ptx_header[2])

if (reducePtx==T){
  # Remove every other point from PTX file
  npoints = dim(dat)[1]
  cols = 0:(npoints-1) %/% ncols
  rows = rep.int(0:(nrows-1),ncols)
  dat1 = dat[cols%%2==0 & rows%%2==0,]
  remove(cols)
  remove(rows)

  # Write output ptx file
  ptx_out = paste0('reduced_',ptx)
  write.table(dat1,ptx_out,append = T,sep=' ',quote=F,row.names = F,col.names = F)}



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?