Skip to content

parzer v0.6.0

Latest

Choose a tag to compare

@AlbanSagouis AlbanSagouis released this 25 Nov 10:31
875d8a8

parzer 0.6.0

NEW FEATURES

  • parse_lat() and parse_lon() have a working format argument (#7, #11). A pattern such as "DDMMSSH" says how the values are written, so packed digits can be read: ICAO "512839N", NMEA "4556.98735" with "DDMM.mmmmm", or "N455698735" with "HDDMMmmmmm" (decimal point not written). Several patterns can be given; each value is read with the first one that matches. Values that do not match, or are out of range, give NA and are listed in one warning. See the new Format section of ?parse_lat.
  • parse_llstr() has a format argument (#11). One pattern describes the whole string, for example "DDMMSSH DDDMMSSH" for an ICAO pair such as "512839N 0002741W". The two coordinates need no separator: "DDMMSSHDDDMMSSH" reads "512839N0002741W", and "HD.ddddHDDD.ddd" reads "N4.9196E101.347", which could not be read before. Several patterns can be given; each string is read with the first one that matches. Strings that do not match, or with a value out of range, are listed in one warning. See the Format section of ?parse_llstr.
  • parse_llstr() has an order argument: "auto" (the default), "lat_lon" or "lon_lat". With "auto", latitude comes first, unless the direction letters only fit longitude first: "W74.5, N45.5" and "74.5W, 45.5" now give lat 45.5 and lon -74.5. Letters that contradict each other ("E45, E30"), or that do not fit a forced order, give NA for both values with a warning. Only rows that gave at least one NA before can change.
  • parse_lon_lat() has lon_format and lat_format arguments, passed to the format argument of parse_lon() and parse_lat(). The longitude comes first, as in the other arguments.

BUG FIX

  • parse_llstr() no longer returns a latitude as the longitude when the values seem to be swapped. When the first value is out of the latitude range but is a valid longitude, and the string has no direction letter, as in "101.347, 4.9196", both values are now NA, with a warning that suggests order = "lon_lat". Before, this gave lat NA and lon 4.9196. Other failures still keep the value that could be read: "abc, -74.5" gives lat NA and lon -74.5. Only these rows, which already had an NA, change.
  • A Unicode minus sign (U+2212), an en dash or an em dash in front of a number is now read as a minus sign. Before, "−45.5" gave 45.5 without a warning.
  • parse_llstr() cuts at the only space whatever the number of decimal points: "45 74.5" gave lat NA and lon 5. A single decimal number such as "45.74" is no longer cut at the dot into two coordinates; it gives NA with a warning. The accepted formats are now listed in the documentation.
  • A number with two decimal points, e.g. "40.25.30", gives NA with a warning instead of silently reading 40.25.
  • NA input gives NA without a warning in all functions. Before, every NA gave a "no digits detected, got: na" warning.
  • A minus sign that disagrees with the hemisphere letter, e.g. "N -45" or "-45N", gives NA with a warning. Before, "N -45" gave 45 and "-45N" gave -45, both silently. "S -45" still gives -45.
  • The degree marks d and g are accepted in upper case too: "40G 25 6N" gave NA.
  • pz_d(1) + 5 and the like now fail with a clear message ("both sides must be pz objects"); unary minus works and keeps the unit: -pz_m(30).
  • pz_degree(), parse_lon_lat() and parse_hemisphere() give plain error messages for a missing argument or a length mismatch.
  • The lifecycle badge figure is now shipped with the package, so the help page no longer shows a broken image.
  • Documentation: invalid values give NA, not NaN.

MINOR IMPROVEMENTS

  • When a value with 4 or more digits in a row (not after a decimal point), such as "2343 56N", gives NA because its degrees, minutes or seconds are out of range, the warning now says that the digits may be packed together and points to the format argument. Before, a latitude warning said to check that lon and lat were not inverted.
  • Faster input cleaning: it now runs in C++, without regular expressions, and turns numbers into text in one step instead of one by one. parse_llstr() also cleans each string once instead of three times. Measured against 0.5.0 on 2026-11-23 on an installed package (macOS arm64, mixed inputs, median times): parse_lat() and parse_lon() take 48 ms instead of 130 ms for 100 000 strings (2.7 times faster), and 70 to 75 ms instead of 1.1 s for 100 000 numbers (about 15 times faster). parse_parts_lat() takes 4.9 ms instead of 13 ms for 10 000 strings, and parse_llstr() 30 ms instead of 70 ms for 20 000 strings.
  • Strings that are not text give an error, with or without format, as invalid UTF-8 already did: strings marked as "bytes" (see ?Encoding), and strings marked as latin1 with one of the 5 bytes that Windows-1252 leaves undefined (0x81, 0x8D, 0x8F, 0x90, 0x9D). Before, a "bytes" string was cleaned byte by byte. Convert such strings to UTF-8 first, for example with iconv().
  • The performance tests now also catch moderate slowdowns, through a relative speed test: the time of parse_lat(), parse_lon() and parse_llstr() on 10 000 strings is divided by the time of a base R gsub() on the same strings and must stay below a limit set from the ratios on 5 CI platforms: 6 for parse_lat() and parse_lon(), 8 for parse_llstr(). The older tests only caught large slowdowns, such as run time growing with the square of the input. The new test runs only on an installed package, not with devtools::test().
  • Removed a check in the C++ code that could never fire, and the Japanese-locale test for the old std::regex bug. callr, pkgbuild, pkgload and withr are no longer suggested.