Giter Site home page Giter Site logo

R/time.R - filename restricted? about pqr HOT 5 OPEN

 avatar commented on July 23, 2024
R/time.R - filename restricted?

from pqr.

Comments (5)

 avatar commented on July 23, 2024

I found the reason for this strange behavior. I had one function saved as (in file date.R):
print.date <- function(x, sep = '-')
Without {} or NULL. It seems that if there is no separator after the function (NULL or {}) then the interpreter will generate difficult to detect errors. I've seen similar problems on the internet and people have trouble determining what causes these errors.

Should I close this application or leave it open. Maybe it's worth adding some checks in the parser?

from pqr.

radfordneal avatar radfordneal commented on July 23, 2024

Was that function with no body the last thing in the date.R file? If not, the following text will be parsed as the body of the function (which is perfectly normal - many functions are defined with the body following function (...) without a { on the same line.

When I try parsing a file with an incomplete function definition at the end, I get "unexpected end of input", both with pqR and with R-3.5.1. But you didn't see such an error? Perhaps it gets generated but then ignored (and not displayed) in the package installation process. If that seems to be the problem, it would help if you posted a tar file of a complete package directory that behaves badly when trying to install.

from pqr.

 avatar commented on July 23, 2024

Here you go:

# cat radford.sh
#!/bin/sh
mkdir -p /tmp/x/R

cat <<EOF > /tmp/x/R/1.R
f1 <- function(x) {}
f2 <- function(x)
EOF

cat <<EOF > /tmp/x/R/2.R
f3 <- function(x) {}
EOF

cat <<EOF > /tmp/x/NAMESPACE
export(f1,f2,f3)
EOF

cat <<EOF > /tmp/x/DESCRIPTION
Package: xxx
Type: Package
Title: x
Version: 0.1
Date: 2019-03-31
Author: x
Depends:
Suggests: 
Maintainer: x <[email protected]>
Description:
LazyLoad: yes
License: MIT
EOF

cd /tmp
R CMD INSTALL x
# 
# sh radford.sh
* installing to library ‘/Library/Frameworks/R.framework/Versions/2.15/Resources/library’
* installing *source* package ‘xxx’ ...
** R
** preparing package for lazy loading
** help
No man pages found in package  ‘xxx’ 
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error in namespaceExport(ns, exports) : undefined exports: f3
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/2.15/Resources/library/xxx’

from pqr.

radfordneal avatar radfordneal commented on July 23, 2024

I think I know what's happening. A clue is that the error message refers to f3, not to f2, which is the function that's missing its body. I think all the .R files are concatenated into one .R file, and then parsed. When this is done, there's no error in the definition of f2, since after concatenating files, it's definition becomes

 f2 <- function (x)
 f3 <- function (x) {}

This defines a function f2 that returns a function as its value, namely the function function(x){}. There is no global definition for f3, since the assignment to f3 is as a local variable of f2.

There's no obvious simple fix. Perhaps package installation should not concatenate source files. Or perhaps there should be a parser directive (a special comment, like #line at present) that signals an error if it is found inside a syntactic construct, which could be included between concatenated files to signal an error in situations like this.

Of course, the nature of the problem will change with the names of the source files, since they determine the order in which the files are concatenated.

from pqr.

 avatar commented on July 23, 2024

Exactly. This was a very strange error message because I knew that the functions indicated in the error were correct. I'm working on a new datetime class. Unfortunately, I'm not satisfied with R's Date and POSIXct.

btw. if you would be interested in refactoring the C code in pqR, I can get involved. The readability would improve and it would be easier to detect errors. #36 (comment)

from pqr.

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.