1  Getting Started

This chapter installs PubMaps and makes a first map. Setting up is done once. After that, a map is one command.

1.1 What you need

  • R, version 4.4 or later. PubMaps was developed with R 4.6. RStudio is convenient but not required.
  • An internet connection. PubMaps sends the manuscript to a language model and looks places up in online gazetteers.
  • An account with a language-model provider. PubMaps works with OpenAI or Anthropic. You need an API key from one of them.
  • A free GeoNames account. Sign up at geonames.org, then turn on web services on your account page. That second step is easy to miss.

1.2 Install PubMaps

PubMaps is an R package. Install it once:

install.packages("remotes")
remotes::install_github("kimbridges/pubmaps")

This also installs the packages PubMaps depends on, including detailed coastlines for small study areas. The first install takes a few minutes.

Two more packages, elevatr and terra, are needed only if you want shaded relief behind the map. They can wait.

1.3 Store your keys and folders

Keys belong in your .Renviron file, not in scripts or documents. Open it with:

usethis::edit_r_environ()

Add the lines that apply to you, save the file, and restart R:

OPENAI_API_KEY=your-openai-key
ANTHROPIC_API_KEY=your-anthropic-key
GEONAMES_USERNAME=your-geonames-name
PUBMAPS_REVIEW=C:/maps/review

You need only one of the two model keys. Without GEONAMES_USERNAME, PubMaps skips GeoNames and uses OpenStreetMap alone, which finds fewer villages.

PUBMAPS_REVIEW is the folder where review folders go. Without it, they go into a folder called review inside R’s working directory. Choose a folder you can find again.

NoteThe gazetteer cache

PubMaps keeps every gazetteer answer, so a second run of the same manuscript makes no new lookups. The cache lives in R’s standard user folder; pubmaps_cache_dir() shows where. To keep it somewhere else, for example on a shared drive, add PUBMAPS_CACHE= and a folder to .Renviron.

NoteGeoNames premium

If you have a premium GeoNames account, add GEONAMES_HOST=https://secure.geonames.net (and GEONAMES_TOKEN=... if your account uses one). With nothing set, PubMaps uses the free server, which allows 10,000 lookups a day. A manuscript needs a few hundred at most, and repeat lookups come from the cache.

1.4 Load PubMaps

At the start of each R session:

library(pubmaps)

1.5 Make a first map

Give pubmap() the manuscript. A PDF is best, because PubMaps reads it page by page and records where each place was found:

pubmap("C:/manuscripts/Medley_et_al_2010.pdf")

PubMaps works through five steps:

  1. Read. The text is extracted from the PDF, one page at a time.
  2. Extract. The language model reads the whole manuscript and returns every mappable place: its name, its role in the study, the page, and the sentence that mentions it. This is one request and takes up to a minute.
  3. Locate. Each place is looked up in GeoNames and OpenStreetMap. OpenStreetMap allows one request a second, so a long manuscript takes a few minutes the first time. Answers are cached, so a second run is quick.
  4. Plan and draw. PubMaps chooses the frame, projection and inset corner, and draws the map.
  5. Write the review folder. Everything goes into a folder named after the manuscript, inside your review folder.

When it finishes, PubMaps prints the path of the review page. Open that file in a web browser. Chapter 2 explains what you will find.

1.6 Choosing the reader

By default the manuscript is read by an OpenAI model. To use Anthropic instead:

pubmap("paper.pdf", provider = "anthropic")

Different models can produce slightly different place lists. Whichever you use is recorded on the review page.

1.7 Redrawing after corrections

After you correct a map (Chapter 3), redraw it by giving pubmap_rerender() the manuscript’s name:

pubmap_rerender("Medley_et_al_2010")

PubMaps finds the review folder of that name in your review folder. The full path of the folder also works, and so does the name with .pdf on the end. The review page shows the command with the folder already filled in, ready to copy.

This does not read the manuscript again or repeat the lookups. It reads your corrections and redraws, usually in a few seconds.

ImportantClose the map PDF first

If the map’s PDF is open in a viewer, Windows will not let PubMaps replace it, and the redraw stops with an error. The same applies to points.csv if it is open in Excel. Close both before redrawing.

1.8 Updating PubMaps

When a new version is released, run the install line again:

remotes::install_github("kimbridges/pubmaps")

Then restart R. Review folders made by an earlier version can be redrawn with the new one; recipe.yaml records which version drew each map.