Closed cahartin closed 7 years ago
This example doesn't work, so I'm not sure exactly what you want. But can't you do
x <- tibble(x = 1:3)
y <- tibble(Non.CO2 = c("CH4","N2O","NMVOC","NOx","SO2","CO","VOC"))
repeat_add_columns(x, y)
maybe...but I don't want to make new df/tibbles, i want to keep everything in the pipeline.
Can you give a clear example of what you want? ...sorry if I'm being slow this morning.
... %>%
repeat_add_columns(tibble(Non.CO2 = c(...))) %>%
Here is the code i'm working on. the ` get messed up below.
GCAM_sector_tech %>% select(supplysector, subsector, stub.technology, EPA_agg_sector, EPA_agg_fuel_ghg, EDGAR_agg_sector) %>% filter(EDGAR_agg_sector %in% c("industry_processes", "chemicals", "landfills", "wastewater","aerosols", "metals","foams","solbvents", "semiconductors")) %>%
repeat_add_columns(tibble::tibble(c("CH4","N2O","NMVOC","NOx","SO2","CO","VOC"))) %>%
rename(Non.CO2 = c("CH4", "N2O", "NMVOC", "NOx", "SO2", "CO", "VOC")`)->
L131.nonco2_pct_R_prc_S_S_2005`
Basically, I was not able to figure out a way to give a specific name to the column being added by repeat_add_columns
without additionally using the rename
command in the next line. And my solution is sadly full of frustration, and I passed it to both CH and CL.
The frustrating thing is that repeat_add_columns
in the above example will automatically name the new column: c("CH4", "N2O", "NMVOC", "NOx", "SO2", "CO", "VOC"). To use in rename
it has to be enclosed with backticks and the spacing has to be absolutely perfect (spaces after commas and nowhere else). If it throws errors, I usually can't see the spacing mistake and have to be in debug mode, use head(whatever the df name is)
, and then copy the column name exactly.
I think what would be nice is if, in the above, we could do
repeat_add_columns(Non.CO2, tibble::tibble(c("CH4","N2O","NMVOC","NOx","SO2","CO","VOC")))
and have the new column be automatically named Non.CO2 without having to manually set it in the next line.
Again though I don't understand. Why aren't you naming it right in the tibble
call?
GCAM_sector_tech %>%
select(supplysector, subsector, stub.technology, EPA_agg_sector, EPA_agg_fuel_ghg, EDGAR_agg_sector) %>%
filter(EDGAR_agg_sector %in% c("industry_processes", "chemicals", "landfills", "wastewater","aerosols", "metals","foams","solbvents", "semiconductors")) %>%
repeat_add_columns(tibble::tibble(Non.CO2 = c("CH4","N2O","NMVOC","NOx","SO2","CO","VOC"))) ->
L131.nonco2_pct_R_prc_S_S_2005
Did not know you could do that! That's the one place I did not try to put it in.
repeat_add_columns(Non.CO2, tibble::tibble...
and repeat_add_columns(Non.CO2= tibble::tibble...
both threw errors, so I just got frustrated and found a workaround.
Sorry if this wasn't clear! Yes, tibble
operates like data.frame
: (name_of_col1 = ...values..., names_of_col2 = ...values..., etc)
I updated the Name that Function page
Thanks Abigail! :1st_place_medal:
Is there a way to we can add the column name right in
repeat_add_columns
rather than going and renaming the column after?example: repeat_add_columns(tibble::tibble(c("CH4","N2O","NMVOC","NOx","SO2","CO","VOC"))) %>% rename(Non.CO2 =
c("CH4", "N2O", "NMVOC", "NOx", "SO2", "CO", "VOC")
)