I have a series of animals that are being radio-tracked.  I have written
some code that goes through each animal and calculates the total distance
that each animal is traveling.  I will need to run these data on a regular
basis and want to write the result to a .php webpage file so that the page
updates automatically when I re-run the code.  I thought I'd be able to use
the "writeLines" command, but this only works for character strings.  In
addition, it doesn't seem to allow me to insert the distance traveled value
where I want it (update Distance where ID=2829, for example).  Does anyone
know of a command that I could write a value to a specific location in .php
code?  I simply need to read a particular line in my .php code, then insert
my distance value into a field value that currently has the value '&nbsp' as
a space holder.  My code is currently:

# Loop through dataset, summarizing data based on Animal name
wild_ID <-unique(wild$ID)
Animal <-unique(wild$Name)
filepath <-"c:/Jared/Data/Kenya/Wildebeest/Summary/"

# Create an empty dataframe
dat3 <- data.frame(Animal)

for (i in c(1:length(wild_ID))) {
 # Create Subset
 dat <-subset(wild, ID == wild_ID[i])
 # Calculate Sum of Movement, put in km
 dat2 <-(sum(dat$STEPLENGTH))/1000
 dat3$Distance[i] <-dat2

 # Write Value to CSV file
 outfile <-paste(filepath,"Animal_Distances",".csv",sep="")
 write.csv(dat3,file=outfile, quote = FALSE, row.names = FALSE)
 # Create PHP connection and export distance traveled to specific
location in PHP code
 PHP <-file(description = "x:/Web/Gnu/tracking_copy_temp.php", open = "r+")

 ###### This is the part that doesn't work.#######
 # Write dat3 value to correct line in code, need where statement
 writeLines(dat3$Distance, con = PHP)

 # Close PHP connection
 close(PHP)
}


Thanks in advance for any suggestions.

Jared

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to