Skip to content

0.5.2#85

Open
ThierryO wants to merge 24 commits intomainfrom
0.5.2
Open

0.5.2#85
ThierryO wants to merge 24 commits intomainfrom
0.5.2

Conversation

@ThierryO
Copy link
Member

fix #81

florisvdh and others added 24 commits February 18, 2026 18:17
In Windows, this avoids that pattern mismatches occur between root and
file. Before, this could lead to not removing the root part from the returned
vector.
Co-authored-by: ThierryO <446636+ThierryO@users.noreply.github.com>
Co-authored-by: ThierryO <446636+ThierryO@users.noreply.github.com>
Co-authored-by: ThierryO <446636+ThierryO@users.noreply.github.com>
Co-authored-by: ThierryO <446636+ThierryO@users.noreply.github.com>
## Description

This PR adds some fixes related to the return value of
`rename_variable()`.

- In the documentation, the description of the return value was wrong
(NULL).
- On Windows it has been observed that the root remains included in the
result, despite `remove_root()` was called. During debugging on Windows,
it was seen that Windows-specific pattern mismatches occurred between
the `root` and `file` arguments of `remove_root()`. These could be
"\\\\" vs. "/" as well as user directory abbreviations. Applying
`normalizePath()` on both inputs of `remove_root()` before calling the
latter, similar to the way this is handled in `write_vc()` (where the
problem doesn't pop up), solved it.
- A test has been added to verify that the root is not part of the
resulting file vector.

I'm pushing this in two steps, hoping to see failure of the tests in
Windows first, then succes after adding the commit that fixes behaviour.
Co-authored-by: ThierryO <446636+ThierryO@users.noreply.github.com>
Co-authored-by: ThierryO <446636+ThierryO@users.noreply.github.com>
Co-authored-by: ThierryO <446636+ThierryO@users.noreply.github.com>
Co-authored-by: ThierryO <446636+ThierryO@users.noreply.github.com>
Yaml doesn't store named vectors. Therefore sort the convert functions.
…mations (#84)

## Description

Implements column-level round-trip transformations. The `convert`
argument allows specifying functions to transform data before storage
and reverse the transformation on read.

**Implementation:**
- `convert` is a named list mapping column names to transformation specs
- Each spec: `c(write = "package::function", read =
"package::function")`
- Write conversions applied before `meta()`, read conversions after
`reinstate()`
- Conversion metadata stored in YAML under `..generic$convert`
- Metadata hash recalculated after adding convert to ensure integrity
- Convert spec added to returned data.frame attributes

**Validation:**
- Verifies column names exist
- Checks package availability via `requireNamespace()`
- Validates function existence in specified package
- Change detection integrated with `compare_meta()` for strict mode
- Refactored validation logic into helper functions to meet cyclomatic
complexity limits

**Files modified:**
- `R/utils.R`: `validate_convert()` and helper functions
(`validate_convert_structure()`, `validate_convert_element()`,
`validate_convert_function()`), plus `apply_convert()`
- `R/write_vc.R`: Added convert parameter, validation, storage, hash
recalculation, and change detection
- `R/read_vc.R`: Read and apply conversions from metadata
- `tests/testthat/test_h_convert.R`: 10 test cases covering validation,
conversions, backward compatibility
- `vignettes/convert.Rmd`: Comprehensive vignette with examples and use
cases
- `vignettes/data_package.Rmd`: Vignette documenting the
`data_package()` function
- `NEWS.md`: Feature documentation

## Related Issue

Addresses issue #81

## Example

```r
library(git2rdata)

data <- data.frame(
  text = c("hello", "world"),
  number = 1:2
)

# Transform text to uppercase for storage, lowercase on read
write_vc(
  data,
  "mydata",
  root = ".",
  sorting = "number",
  convert = list(
    text = c(
      write = "base::toupper",
      read = "base::tolower"
    )
  ),
  digits = 6
)

# TSV file contains: "HELLO", "WORLD"
result <- read_vc("mydata", root = ".")
result$text  # Returns: "hello", "world"
attr(result, "convert")  # Contains conversion spec
```

Multiple columns supported:
```r
convert = list(
  col1 = c(write = "pkg1::func1", read = "pkg1::func2"),
  col2 = c(write = "pkg2::func3", read = "pkg2::func4")
)
```

See `vignette("convert", package = "git2rdata")` for detailed usage
examples.

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/ropensci/git2rdata/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add integer64 support

3 participants