Merge a primary alias station and all of its secondary aliases/data sources and associated data with another existing primary alias station as a secondary alias by providing a dataframe with the columns "station_name", "station_id", and "target_primary_alias."

This function requires that both the station and its target are primary aliases. Moving a non-primary alias can currently only be done in EnviroData by first turning it into a primary alias of its own by separating it from its primary alias.

This function uses the /api/dataSources/discrete_envirodata/ID/MFID endpoint, which is found both on the manage > monitoring locations page and each station's summary page.

merge_existing_stations(master_df)

Arguments

master_df

Dataframe with columns of "station_name", "station_id", "target_primary_alias_name", "is_test_run_" and "is_qaqc.' See below for details.

station_name: the current primary alias name of the station you want to move. Values can be found in the Location column of the return value from function get_wq_locations_list.

station_id: the ID of the station that you want to move. This value can also be found in the return value from from function get_wq_locations_list. Note that this is not the monitoring feature ID, but rather the ID of the monitoring feature's primary alias/data source/station.

target_primary_alias_name: the name of the primary alias/data source/station of a monitoring location that you want to merge into. The primary alias name of a station/data source/alias is the same as the encompassing monitoring location's name. Values can be found using the Location column of the return value of get_wq_locations_list.

is_test_run: Boolean value of whether this should be a test run. A test run makes no changes to the system but allows you to see the resulting logs of what would hypothetically happen if you ran the code for real.

is_qaqc: Boolean value. If true, the station being moved will be set as a QAQC alias of the target station.

Value

The original master dataframe with a new "result" column that contains the response from each request.

Examples

  # Example master_df
  master_df_example <- data.frame(
    station_name = c("StationToMerge1", "StationToMerge2"),
    station_id = c(123, 456),
    target_primary_alias_name = c("TargetStation1", "TargetStation2"),
    is_test_run = c(FALSE, FALSE),
    is_qaqc = c(FALSE, FALSE)
  )

  # Call the merge_existing_stations function
  merged_stations <- merge_existing_stations(master_df = master_df_example)

  # View the results
  print(merged_stations)