Dear Guillaume Vareille,

В Wed, 20 Sep 2023 12:30:53 +0200
tinyfiledial...@ysengrin.com пишет:

> I've been pointed to the documentation link on how to write a package,
> but it would really help if someone who knows what to do could direct
> me.

There's potentially a lot to tell. Converting the entire Writing R
Extensions [*] into e-mails is a poor use of one's time. Do you have
more specific questions? If you don't know where to start, try
utils::package.skeleton or the pkgKitten package (which aims to pass R
CMD check right from the start). There's also books like R Packages by
Hadley Wickham and Jennifer Bryan, but they mention a lot of techniques
and third-party dependencies that you don't have to use.

>      # first load the included library (it could easily be compiled
> on the target machine)
>      dyn.load("tinyfiledialogsLinux64.so")

You will need to put your source files into the src/ subdirectory of
the package and arrange for them to get compiled (see WRE 1.1.5 and
1.2.1). It's best to write a special entry point in order to let R know
about the functions you intend to call (see WRE 5.4).

Does your code have third-party dependencies? If you'd like to put the
package on CRAN, you will need to bundle your own code with the package
(since it's probably not available yet in major GNU/Linux
distributions, macOS recipes and MXE) but set up a ./configure script
to locate the third-party dependencies while the package is being
installed: https://cran.r-project.org/web/packages/external_libs.html

>        result <- .C("tfd_openFileDialog",
>              charToRaw(aTitle),

In R, strings have encodings. A string can be stored in UTF-8, Latin-1,
the native locale encoding (which may include anything from
Windows-936 to KOI8-R) or even as arbitrary bytes, which admittedly
makes it less of a string (see ?Encoding).

x1 <- `Encoding<-`('fran\xe7ais', 'latin1')
x2 <- `Encoding<-`('fran\xc3\xa7ais', 'UTF-8')
x1 == x2 # TRUE, they encode the same characters
identical(charToRaw(x1), charToRaw(x2)) # not even the same length

Which encoding does tfd_openFileDialog() use for the file names and
paths? Does it work with UCRT on Windows in UTF-8 locale mode? (Can you
return a filename that is not representable in the ANSI codepage?) You
will probably need to convert the strings into a certain encoding before
passing them to tfd_openFileDialog(...) (e.g. enc2utf8(.)).

>        if ( result$lOpenFile == "NULL" ) return()

What happens if I create a file named NULL on my system and try to open
it?

Good luck, and I hope that your effort results in a good R package!

-- 
Best regards,
Ivan

[*] https://cran.r-project.org/doc/manuals/R-exts.html

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to