我是R的新手。有人可以解决以下错误吗?
transxchange_XML_load(bus_file)中的错误:找不到函数 “ trans_xchange_XML_load”
这是一些代码,用于在高峰时段解析transxchange数据并提取服务。
我应该以一个输出文件夹结尾,该文件夹包含在正常(非节假日)的高峰时段运行的所有服务。
library(dplyr)
library(assertive, warn.conflicts = FALSE)
library(ggplot2)
library(XML)
library(lubridate)
library(leaflet)
#bus_stops<-read.csv("/mnt/d7833fca-ae99-4c08-a207-fce383635e96/public transport/NaPTANcsv/Stops.csv",sep=',',header=T,stringsAsFactors = F)
#bus_file<-"/mnt/d7833fca-ae99-4c08-a207-fce383635e96/public transport/NE/NE_410_PA0019SIN_1.xml"
file_list<-list.files("C:/Users/b6051089/OneDrive - Newcastle University/GIS Data/PTAL/transxchange/All")
file_list1<-list.files("C:/Users/b6051089/OneDrive - Newcastle University/GIS Data/PTAL/transxchange/rush hour/")
for (bf in file_list[53:length(file_list)]){
bus_file<-paste0("C:/Users/b6051089/OneDrive - Newcastle University/GIS Data/PTAL/transxchange/All",
bf)
print(bf)
result<-c()
#this loads up the data from the xml transxchange file
transxchange_XML_load(bus_file)
#create a list of journeys for the data
journeys<-journey_list(JourneyPatternSections)
#create the stop point list
stop_points<-stop_point_load(StopPoints)
#create the vehicle dataframe. This is the departure time and operating date/time for each journey
vehicles<-VehicleJourneys_to_dataframe(VehicleJourneys)
#pick out the rushhour mondayto friday trips
s<-which( (vehicles$op_days=="MondayToFriday" & hour(hms(vehicles$dep_time))==7) | (vehicles$op_days=="MondayToFriday" & hour(hms(vehicles$dep_time))==8))
#matches journeypatternref with journeypatternid
services<-services_lookup(Services)
#create the timetables
timetables<-timetable(vehicles,journeys,services)
#pull out one journey plus data
#then use loess to interpolate around duplicated times
#then join to naptan data to retrieve lat/long
for(j in s){
#print(j)
trip<-timetables[[j]][[4]]
sp=max(0.1,1/length(trip[,1]))
trip<-trip%>%mutate(time=hms(trip$times))%>%
mutate(seconds=as.numeric(time-time[1]))%>%
mutate(x=1:length(time))%>%
mutate(seconds=floor(loess(seconds~x,data=trip,span=sp)$fitted))%>%
mutate(time_adjusted=dmy_hms(paste("01-01-2000",times[1]))+seconds)%>%
select(stops,times,time_adjusted)%>%mutate(trip_id=j)
#left_join(bus_stops,by=c("stops"="ATCOCode"))%>%
#select(stops,times,time_adjusted,Easting,Northing,Longitude,Latitude)%>%
# mutate(trip_id=j)
result<-rbind(result,trip)
}
write.csv(result,
file=paste0("C:/Users/b6051089/OneDrive - Newcastle University/GIS Data/PTAL/transxchange/rush hour/",gsub('.xml','.csv',bf)),
quote=F,row.names = F)
} ```
答案 0 :(得分:0)
一个快速的Google会在包transxchangeR中显示一个具有确切功能名称的包:https://rdrr.io/github/Hillbert/transxchangeR
要安装它,页面会为您提供
install.packages("remotes")
remotes::install_github("Hillbert/transxchangeR")