R/Xrow_to_Perl.R

"Xrow_to_Perl" <- function(x, row=1, file="", comment=NA) {
  x <- as.data.frame(x)
  nm <- names(x)
  rw <- x[row,]

  if(! is.na(comment)) {
    cat(paste0("# ",comment,"\n"), file=file)
  }
  cat(paste0("$ROW = ",row,";\n"), file=file)
  cat("$X = {\n", file=file)
  for(i in 1:(length(nm)-1)) {
    if(is.na(rw[i])) rw[i] <- '"infinity"'
    cat(paste0("   ",nm[i], " => ", rw[i],",\n"), file=file)
  }
  cat(paste0("   ",nm[length(nm)], " => ",
                   rw[length(nm)],"};\n"), file=file)
}
wasquith-usgs/Cubist.Idioms documentation built on Jan. 1, 2021, 12:45 p.m.