Giter Club home page Giter Club logo

Comments (4)

lionel- avatar lionel- commented on July 17, 2024

I'm not sure what you're expecting here. But please note that rlang::duplicate() is for expert usage only. It's a direct wrapper around the C-level function of the R API which most certainly works as expected according to its specifications.

from rlang.

Yunuuuu avatar Yunuuuu commented on July 17, 2024

Thank you for the clarification. I understand that rlang::duplicate() is a powerful function that directly wraps a C-level function in the R API. I mean the names of dt1 shouldn't change when I change dt2 by reference just like what dt3 worked. dt3 is a data.table created via dt1[TRUE] which has been revealed to do shallow copy.

from rlang.

Yunuuuu avatar Yunuuuu commented on July 17, 2024

dt2 has removed the name "mpg" in dt1

dt2[, mpg := NULL]
x
#>  [1] "cyl"  "disp" "hp"   "drat" "wt"   "qsec" "vs"   "am"   "gear" "carb"
names(dt1)
#>  [1] "cyl"  "disp" "hp"   "drat" "wt"   "qsec" "vs"   "am"   "gear" "carb"

from rlang.

lionel- avatar lionel- commented on July 17, 2024

It's not that it's powerful, it's that it's extremely low level, and you shouldn't expect any high level semantics from it. Also it's mostly meant for prototyping C code from R and should generally not be used in user or package code.

dt2 has removed the name "mpg" in dt1

Yes since it's a shallow copy the attributes list is not duplicated, which means that if you modify the names in place later on you'll get side effects. It's all working as expected from the perspective of these very low level tools.

from rlang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.