Closed bwmatherne closed 2 years ago
There are only a handful of pcodes that will have a default set for the renameNWISColumns
function. You check out the help page here:
http://usgs-r.github.io/dataRetrieval/reference/renameNWISColumns.html
and see the preset names are:
If you want to define 00480 as "Salinity", you can do this (the other defaults will remain):
sitesLA <- renameNWISColumns(sitesLA, p00480="Salinity")
names(sitesLA)
[1] "agency_cd" "site_no" "dateTime"
[4] "Wtemp_Inst" "Wtemp_Inst_cd" "Flow_Inst"
[7] "Flow_Inst_cd" "Salinity_Inst" "Salinity_Inst_cd"
[10] "tz_cd"
I think you are then requesting that the attribute variableInfo
gets updated when this function is run. My instinct is to push back on that request because the variableInfo information is direct metadata from NWIS, and the renameNWISColumns
is a simple convenience function to change some column headers. There are more complicated data sets that come back with multiple columns of the same parameter (for a variety of reasons, maybe the samples are at different depths, maybe facing upstream vs downstream, maybe different statistic codes), which would make this request more complicated.
If you wanted to join those short column names with the variableInfo attribute, you could do something like this:
variableInfo <- attr(sitesLA, "variableInfo")
variableInfo <- variableInfo |>
dplyr::left_join(data.frame(variableCode = c("00010","00060","00480"),
shortName = c("Wtemp", "Flow", "Salinity"),
columnNames = c("Wtemp_Inst", "Flow_Inst", "Salinity_Inst")),
by = "variableCode")
I'm not sure what the problem_query was trying to show:
problem_query <- readNWISdv("a","b","c","d")
If you call readNWISdv
with those inputs. What you are pasting in there is siteNumbers is "a", parameterCd is "b", startDate is "c", and endDate is "d". The first error message that stops the function is that parameter code is not right (since it needs to be a 5 digit character).
Let me know if I mis-understood. Thanks!
Laura,
Thank you for such a quick reply. I had been manually changing the labels, but I was worried if this would create other problems as I progress with the datasets that I’m working on. Everything you stated is quite clear and helpful.
Take care,
Brian
Brian W. Matherne Doctoral Candidate Department of Environmental Sciences Louisiana State University 3259 Energy, Coast, & Environment Bldg., Baton Rouge, LA 70803 mobile 225-772-6126 @. @.> | lsu.edu http://www.lsu.edu/ | www.environmental.lsu.edu/ http://www.environmental.lsu.edu/
On May 16, 2022, at 1:11 PM, Laura DeCicco @.***> wrote:
There are only a handful of pcodes that will have a default set for the renameNWISColumns function. You check out the help page here: http://usgs-r.github.io/dataRetrieval/reference/renameNWISColumns.html http://usgs-r.github.io/dataRetrieval/reference/renameNWISColumns.html and see the preset names are: https://user-images.githubusercontent.com/1105215/168653932-61f8c12a-8b66-48dc-a904-80bdac75f129.png If you want to define 00480 as "Salinity", you can do this (the other defaults will remain):
sitesLA <- renameNWISColumns(sitesLA, p00480="Salinity") names(sitesLA) [1] "agency_cd" "site_no" "dateTime"
[4] "Wtemp_Inst" "Wtemp_Inst_cd" "Flow_Inst"
[7] "Flow_Inst_cd" "Salinity_Inst" "Salinity_Inst_cd" [10] "tz_cd" I think you are then requesting that the attribute variableInfo gets updated when this function is run. My instinct is to push back on that request because the variableInfo information is direct metadata from NWIS, and the renameNWISColumns is a simple convenience function to change some column headers. There are more complicated data sets that come back with multiple columns of the same parameter (for a variety of reasons, maybe the samples are at different depths, maybe facing upstream vs downstream, maybe different statistic codes), which would make this request more complicated.If you wanted to join those short column names with the variableInfo attribute, you could do something like this:
variableInfo <- attr(sitesLA, "variableInfo")
variableInfo <- variableInfo |> dplyr::left_join(data.frame(variableCode = c("00010","00060","00480"), shortName = c("Wtemp", "Flow", "Salinity"), columnNames = c("Wtemp_Inst", "Flow_Inst", "Salinity_Inst")), by = "variableCode") I'm not sure what the problem_query was trying to show:
problem_query <- readNWISdv("a","b","c","d") If you call readNWISdv with those inputs. What you are pasting in there is siteNumbers is "a", parameterCd is "b", startDate is "c", and endDate is "d". The first error message that stops the function is that parameter code is not right (since it needs to be a 5 digit character).
Let me know if I mis-understood. Thanks!
— Reply to this email directly, view it on GitHub https://github.com/USGS-R/dataRetrieval/issues/615#issuecomment-1127981601, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMWMH3SRL4K4VOVKQZ6Z2A3VKKFVHANCNFSM5WCHFEFA. You are receiving this because you authored the thread.
Describe the bug When downloading data, the salinity code 00480 does not work with renameNWISColumns. This creates issues with other downstream steps such as attr() that can't pull the variable details to easily label figures.
To Reproduce pCode <- c("00010","00060","00480") siteNo <- c("295124089542100","294925089532101","073745257","07374526") start.date <- "2007-10-01" end.date <- "2012-05-31" sitesLA <- readNWISuv(siteNo, pCode,start.date, end.date) sitesLA <- renameNWISColumns(sitesLA) names(sitesLA)
Expected behavior All parameters should be properly renamed and work with other R code to make human readable labels.
Screenshots
Session Info Please include your session info:
Additional context Add any other context about the problem here.