Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[Bug]: `within` doesn't replace the lefthand side of an expression.

Đang mở
#275 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
r
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện các ví dụ được báo cáo liên quan đến within, qenv() và eval_code, sau đó kiểm tra triển khai của within và các liên kết tài liệu của nó. Xác nhận cách vế trái được phân giải, kiểm tra xem mục tài liệu @aliases within có bị thiếu hay không, và coi công việc là hoàn tất khi hành vi biến đổi dự kiến và việc tra cứu ?within đã được bao phủ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug core
What happened?

I wanted to mutate a variable by using as.factor but I found that using this approach doesn't replace the content but creates a new column:

library("teal.code")
var <- "Species"
q <- within(qenv(),
  {
    library("dplyr")
    iris <- iris
    iris2 <- mutate(iris, a = as.factor(a))
  },
  a = as.name(var)
)
setdiff(colnames(q$iris2), colnames(q$iris))
#> [1] "a"

Created on 2025-10-24 with reprex v2.1.1

One workaround is to use the dplyr's walrus := assignment:

library("teal.code")
var <- "Species"
q <- within(qenv(),
  {
    library("dplyr")
    iris <- iris
    iris2 <- mutate(iris, a := as.factor(a))
  },
  a = as.name(var)
)
setdiff(colnames(q$iris2), colnames(q$iris))
#> character(0)

Created on 2025-10-24 with reprex v2.1.1

but this might confuse readers of the code if this end up on the Show R code on teal.
If not a bug perhaps mentioning this on the documentation would be helpful to users.

Also, I realized that within doesn't have the @aliases within so users searching with ?within will not find it (but it is linked from eval_code and qenv).

sessionInfo()

Relevant log output

Code of Conduct
  • I agree to follow this project's Code of Conduct.
Contribution Guidelines
  • I agree to follow this project's Contribution Guidelines.
Security Policy
  • I agree to follow this project's Security Policy.
Ngôn ngữ chính
R
Star
12
Fork
11
Merge trung bình
8 ngày 15 giờ
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của insightsengineering/teal.code

Tất cả issue của insightsengineering/teal.code

Issue tương tự

Thêm issue về R

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.