question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Every now and then I wonder “should this kind of function be in Ramda?”. I just went over the docs for Python’s Pandas library (R-like DataFrames), trying to get a sense of parts it currently made more convenient. Among these was an object to rename columns in a dataframe. I couldn’t directly see a Ramda equivalent easier than some combination of pipe, toPairs, map, and fromPairs, so given that I’d propose a R.rename({ a: 'b', foo: 'bar' }, { a: 1, foo: 2 }) -> { b: 1, bar: 2 }. Pretty random, I know, especially since Pandas is by no means a direct competitor to Ramda users. Otherwise maybe fun for cookbook. Now to get corrected on a super-straightforward equivalent after all!

On a side-note, other bits that stood out to me from its cheat sheet as not having evident Ramda equivalents were NA handling (we’d probably end up deferring to Maybes?) / sparse data, stat-like functions e.g. binning into quartiles/percentiles, as well as maybe pivoting/unpivoting (which is kinda interesting too). Not a common comparison, I know, but that’s why I felt it’d be interesting to check. 😃

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
nicohvicommented, Jun 23, 2017

Not to revive an old issue, but if someone runs into the case rewriting one or few keys, and feel like creating a custom function for all fields to be included seems like overkill I solved it this way:

const renameKeys = keyMap => obj => {
  return R.reduce((acc, key) => {
    keyMap[key] ? acc[keyMap[key]] = obj[key]
    : acc[key] = obj[key]
    return acc;
  }, {}, R.keys(obj));
};
4reactions
chughes87commented, Aug 20, 2019

I found that you could also make creative use of over and lens along with dissoc to do a rename:

const renameXZ = pipe(over(lens(prop('x'), assoc('z')), identity), dissoc('x'));
renameXZ({x: 1, y: 2}); // { y: 2, z: 1 }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Rename columns - dplyr
rename () changes the names of individual variables using new_name = old_name syntax; rename_with() renames columns using a function.
Read more >
dplyr Rename() - To Change Column Name
rename_with() function is from R dplyr library that can be used to rename all data frame columns. In the below example let's use...
Read more >
Rename Data Frame Columns in R - Datanovia
In this tutorial, you will learn how to rename the columns of a data frame in R.This can be done easily using the...
Read more >
3.8 Rename variables | An Introduction to R for Research
You can rename a variable in a dataset by changing a value in the names() vector (base R) or by using the rename()...
Read more >
How to Rename Column (or Columns) in R with dplyr
To rename a column in R, you can use the rename() function from dplyr. For example, if you want to rename the column...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found