1

I'm currently trying to loop through my shapefile of telemetry locations to calculate kernel densities using the 'PLUGIN' bandwidth. I tried the following code in R to create a script that can be loaded into Geospatial Modeling Environment:

uniqueids <- unique(Locations_2001$Animal_ID)

for (i in 1:length(uniqueids))
  {cat(”kde(in=\”Locations_2001.shp\”,out=\”kde_”,uniqueids[i],”.img\”, bandwidth=\”PLUGIN\”,cellsize=30,where=\”Animal_ID=’”,uniqueids[i],”’\”);\n”, sep='')}

I literally built the code from the code listed in the Geospatial Modeling Environment PDF:

uniqueids <- unique(ANIMALID)
for (i in 1:length(uniqueids)){
cat(”kde(in=\”telemetry.shp\”, out=\”kde_”, uniqueids[i], ”.img\”, bandwidth=\”SCV\”, cellsize=20,
where=\”ANIMALID=’”, uniqueids[i], ”’\”);\n”, sep=””)}

My end goal is to get a script like the one in the PDF that can be saved and loaded into GME:

kde(in=”telemetry.shp”, out=”kde M01.img”, bandwidth=”SCV”, cellsize=20,
where=”ANIMALID=’M01’”);
kde(in=”telemetry.shp”, out=”kde F01.img”, bandwidth=”SCV”, cellsize=20,
where=”ANIMALID=’F01’”);
kde(in=”telemetry.shp”, out=”kde M02.img”, bandwidth=”SCV”, cellsize=20,
where=”ANIMALID=’M02’”);
kde(in=”telemetry.shp”, out=”kde F02.img”, bandwidth=”SCV”, cellsize=20,
where=”ANIMALID=’F02’”);
kde(in=”telemetry.shp”, out=”kde J01.img”, bandwidth=”SCV”, cellsize=20,
where=”ANIMALID=’J01’”);

However, I get the following error when I run my code above:

Error: unexpected input in:
"for (i in 1:length(uniqueids))
  {cat(”"
where=\”Animal_ID=’”,uniqueids[i],”’\”);\n”, sep='')}
Error: unexpected input in "where=\"

What am I doing wrong in the above code?

  • You have fancy quotes in your example, is this from your actual code? R will not accept fancy quotes, they need to be plain (ie., " or ' and not ” ). I am also not following your quotes, some are the double and some the single style. It needs to be one or the other and cannot be mixed. One example is your calls to where eg., where=”ANIMALID=’J01’” I suppose this could be a GME thing but is not compatible with R syntax. – Jeffrey Evans Apr 26 '17 at 18:10
  • @JeffreyEvans, thanks for the reply! I was just copying and pasting the script from GME into R so I could develop a quick script that runs through each animal. I too am a little confused on why they use the different quotes. This is likely where the error is coming from but I don't know how else to solve it. Alternatively, I can just manually enter the "in file" and "out file" in the GME GUI; however, I don't know how to use the "where" clause to have GME loop through each of my animal IDs. – Buck2079 Apr 26 '17 at 18:16
  • Sorry, I am fairly fluent in R but can only speculate with GME and how it is parsing information to R. I would recommend just using R for your analysis. The adehabitat, adehabitatHR and ks packages have all of the functionality that you need and, much, much more. I would recommend contacting the author Hawth Beyer. – Jeffrey Evans Apr 26 '17 at 18:24
  • @JeffreyEvans, thanks for the reply! I've contacted Hawthorn Beyer. I've tried using R and adehabitatHR but I'm not extremely fluent in R so I'm a little confused on the coding for the PLUGIN bandwidth kernel density estimation. – Buck2079 Apr 27 '17 at 0:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.