Feil ved bruk commandArgs () for å passere argumenter til R script

stemmer
0

Glad mandag!

Jeg prøver å få min script å lese i en csv-fil gitt fra kommandolinjen, men jeg får stadig denne feilmeldingen:

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

Dette er min kode:

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))

Det er ment å lese i avstand og grad data for å regne ut høyden på trær, legge høyden til dataframe og utgang til en ny fil. Eventuelle hjelpe ville være mye verdsatt, takk! : D

Publisert på 02/12/2019 klokken 23:58
kilden bruker
På andre språk...                            


1 svar

Feil ved bruk commandArgs () for å passere argumenter til R script

stemmer
0

Glad mandag!

Jeg prøver å få min script å lese i en csv-fil gitt fra kommandolinjen, men jeg får stadig denne feilmeldingen:

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

Dette er min kode:

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))

Det er ment å lese i avstand og grad data for å regne ut høyden på trær, legge høyden til dataframe og utgang til en ny fil. Eventuelle hjelpe ville være mye verdsatt, takk! : D

Svarte 02/12/2019 kl. 23:58
kilden bruker

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