Fehler beim commandArgs () mit Argumenten R Skript übergeben

stimmen
0

Happy Monday!

Ich versuche, mein Skript zu erhalten in einer CSV-Datei von der Kommandozeile zu lesen gegeben, aber ich halte diesen Fehler:

Amys-MBP:Code amy$ Rscript get_TreeHeight.R trees.csv
Error in make.names(col.names, unique = TRUE) : 
  invalid multibyte string at '<cf><fa><ed><fe><07>'
Calls: read.csv -> read.table -> make.names
In addition: Warning messages:
1: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 1 appears to contain embedded nulls
2: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 2 appears to contain embedded nulls
3: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 3 appears to contain embedded nulls
4: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  incomplete final line found by readTableHeader on '/usr/local/Cellar/r/3.6.1_1/lib/R/bin/exec/R'
Execution halted

Dies ist mein Code:

args = commandArgs(trailingOnly=FALSE)

MyTrees <- read.csv(args[1], header=TRUE)

TreeDistance <- MyTrees[[2]]

TreeDegrees <- MyTrees[[3]]

TreeHeight <- function(degrees, distance){ 
  radians <- degrees * pi / 180 
  height <- distance * tan(radians) 
  print(paste(height))
}

Tree.Height <- TreeHeight(TreeDegrees, TreeDistance)

MyTrees$Tree.Height.m <- Tree.Height

filename <- tools::file_path_sans_ext(args[1])

write.table(paste0(MyTrees, file = ../Results/,filename,_treeheights.csv, row.names=FALSE, col.names=TRUE))

Es soll in der Entfernung und der Grad, Daten lesen, die Höhe der Bäume zu arbeiten, fügen Höhe der Datenrahmen und Ausgabe in eine neue Datei. Jede Hilfe wäre sehr willkommen, danke! : D

Veröffentlicht am 02/12/2019 um 23:58
quelle vom benutzer
In anderen Sprachen...                            


1 antworten

Fehler beim commandArgs () mit Argumenten R Skript übergeben

stimmen
0

Happy Monday!

Ich versuche, mein Skript zu erhalten in einer CSV-Datei von der Kommandozeile zu lesen gegeben, aber ich halte diesen Fehler:

Amys-MBP:Code amy$ Rscript get_TreeHeight.R trees.csv
Error in make.names(col.names, unique = TRUE) : 
  invalid multibyte string at '<cf><fa><ed><fe><07>'
Calls: read.csv -> read.table -> make.names
In addition: Warning messages:
1: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 1 appears to contain embedded nulls
2: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 2 appears to contain embedded nulls
3: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 3 appears to contain embedded nulls
4: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  incomplete final line found by readTableHeader on '/usr/local/Cellar/r/3.6.1_1/lib/R/bin/exec/R'
Execution halted

Dies ist mein Code:

args = commandArgs(trailingOnly=FALSE)

MyTrees <- read.csv(args[1], header=TRUE)

TreeDistance <- MyTrees[[2]]

TreeDegrees <- MyTrees[[3]]

TreeHeight <- function(degrees, distance){ 
  radians <- degrees * pi / 180 
  height <- distance * tan(radians) 
  print(paste(height))
}

Tree.Height <- TreeHeight(TreeDegrees, TreeDistance)

MyTrees$"Tree.Height.m" <- Tree.Height

filename <- tools::file_path_sans_ext(args[1])

write.table(paste0(MyTrees, file = "../Results/",filename,"_treeheights.csv", row.names=FALSE, col.names=TRUE))

Es soll in der Entfernung und der Grad, Daten lesen, die Höhe der Bäume zu arbeiten, fügen Höhe der Datenrahmen und Ausgabe in eine neue Datei. Jede Hilfe wäre sehr willkommen, danke! : D

Beantwortet am 02/12/2019 um 23:58
quelle vom benutzer

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more