Wesołego poniedziałku!
Staram się, aby mój skrypt do odczytu w pliku csv danej z linii poleceń, ale wciąż otrzymuję ten błąd:
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
To jest mój kodu:
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))
To ma czytać w odległości i danych stopnia wypracowania wysokość drzew, dodać wysokość do dataframe i wyjścia do nowego pliku. Każda pomoc będzie mile widziane, dziękuję! :RE